0% found this document useful (0 votes)
36 views

FactFiboCube and Calender

The document contains code examples for performing various operations like calculating factorials, currency conversion, finding the cube of a number, generating Fibonacci series, and using a calendar control. The calendar control code demonstrates setting calendar properties, retrieving dates, highlighting dates, and resetting selections.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views

FactFiboCube and Calender

The document contains code examples for performing various operations like calculating factorials, currency conversion, finding the cube of a number, generating Fibonacci series, and using a calendar control. The calendar control code demonstrates setting calendar properties, retrieving dates, highlighting dates, and resetting selections.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

Note : If the Code is for a web page

then make sure you do not mess with


the first two lines of your own aspx
file( HTML to HTML only! ) and also
do not change namespace and class
name in your own c# file!
Create simple application to perform following operations

1. Finding factorial Value


2. Money Conversion
3. Cube of given Number
4. Generate Fibonacci series
Code :

Factorial

using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace AWP_Practicals
{
class Program
{
static void Main(string[] args)
{
int i, number, fact;
Console.WriteLine("Enter the Number");
number = int.Parse(Console.ReadLine());
fact = number;
for (i = number - 1; i >= 1; i--)
{
fact = fact * i;
}
Console.WriteLine("\nFactorial of Given Number is: " + fact);
Console.ReadLine();
}
}
}

Money Conversion

using System;
using System.Collections.Generic;
using System.Diagnostics.Metrics;
using System.Linq;
using System.Text;
namespace AWP_Practicals
{
class Program
{
static void Main(string[] args)
{
int choice;
Console.WriteLine(" Enter your Choice:\n 1 - Dollar to Rupee \n 2 - Euro to Rupee \n 3 -
Malaysian Ringgit to Rupee ");
choice = int.Parse(Console.ReadLine());
switch (choice)
{
case 1:
Double dollar, rupee, val;
Console.WriteLine(" Enter the Dollar Amount :");
dollar = Double.Parse(Console.ReadLine());
Console.WriteLine(" Enter the Dollar Value :");
val = double.Parse(Console.ReadLine());
rupee = dollar * val;
Console.WriteLine($"{dollar} Dollar Equals {rupee} Rupees ");
break;
case 2:
Double Euro, rupe, valu;
Console.WriteLine(" Enter the Euro Amount :");
Euro = Double.Parse(Console.ReadLine());
Console.WriteLine(" Enter the Euro Value :");
valu = double.Parse(Console.ReadLine());
rupe = Euro * valu;
Console.WriteLine($"{Euro} Euro Equals {rupe} Rupees ");
break;
case 3:
Double ringit, rup, value;
Console.WriteLine(" Enter the Ringgit Amount :");
ringit = Double.Parse(Console.ReadLine());
Console.WriteLine(" Enter the Ringgit Value :");
value = double.Parse(Console.ReadLine());
rup = ringit * value;
Console.WriteLine($"{ringit} Malaysian Ringgit Equals {rup} Rupees ");
break;
}
Console.ReadLine();
}
}
}

Cube

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace C_Tutorial
{
internal class Class1
{
public double cube;

public double Cube


{
set { cube = GetCube(value); }
}

private double GetCube(double value)


{
double cube = value * value * value;
return cube;
}
}

class MainClass
{
public static void Main(string[] args)
{
Class1 class1 = new Class1();
class1.Cube = 5.10;
Console.WriteLine("Cube : "+ class1.cube);
Console.ReadKey();
}
}
}

Fibonacci series

using System;
namespace AWP_P1_A
{
internal class Program
{
static void Main(string[] args)
{
// Fibonacci Series

int n1 = 0, n2 = 1, n3, i1, number;


Console.Write("Enter the number of elements: ");
number = int.Parse(Console.ReadLine());
Console.Write(n1 + " " + n2 + " ");
for (i1 = 2; i1 < number; ++i1)
{
n3 = n1 + n2;
Console.Write(n3 + " ");
n1 = n2;
n2 = n3;
}
}
}
}
Demonstrate the use of calender control to perform the following
operations

Code:

C# Code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebApplication1
{
public partial class Register : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

protected void btnResult_Click(object sender, EventArgs e)


{
Calendar1.Caption = "AWP Practical";
Calendar1.FirstDayOfWeek = FirstDayOfWeek.Sunday;
Calendar1.NextPrevFormat = NextPrevFormat.ShortMonth;
Calendar1.TitleFormat = TitleFormat.Month;

Label2.Text = "Todays Date" + Calendar1.TodaysDate.ToShortDateString();


Label3.Text = "Ganpati Vacation Start: 19-9-2023";
TimeSpan d = new DateTime(2023, 9, 19) - DateTime.Now;
Label4.Text = "Days Remaining For Ganpati Vacation:" + d.Days.ToString();
TimeSpan d1 = new DateTime(2023, 12, 31) - DateTime.Now;
Label5.Text = "Days Remaining for New Year:" + d1.Days.ToString();
if (Calendar1.SelectedDate.ToShortDateString() == "9-13-2018")
Label3.Text = "<b>Ganpati Festival Start</b>";
if (Calendar1.SelectedDate.ToShortDateString() == "9-23-2018")
Label3.Text = "<b>Ganpati Festival End</b>";
}

protected void Calendar1_DayRender(object sender,


System.Web.UI.WebControls.DayRenderEventArgs e)
{
if (e.Day.Date.Day == 5 && e.Day.Date.Month == 9)
{
e.Cell.BackColor = System.Drawing.Color.Yellow;
Label lbl = new Label();
lbl.Text = "<br>Teachers Day!";
e.Cell.Controls.Add(lbl);
Image g1 = new Image();
g1.ImageUrl = "td.jpg";
g1.Height = 20;
g1.Width = 20;
e.Cell.Controls.Add(g1);
}
if (e.Day.Date.Day == 13 && e.Day.Date.Month == 9)
{
Calendar1.SelectedDate = new DateTime(2018, 9, 12);
Calendar1.SelectedDates.SelectRange(Calendar1.SelectedDate,
Calendar1.SelectedDate.AddDays(10));
Label lbl1 = new Label();
lbl1.Text = "<br>Ganpati!";
e.Cell.Controls.Add(lbl1);
}
}
protected void btnReset_Click(object sender, EventArgs e)
{
Label1.Text = "";
Label2.Text = "";
Label3.Text = "";
Label4.Text = "";
Label5.Text = "";
Calendar1.SelectedDates.Clear();
}

protected void Calendar1_SelectionChanged(object sender, EventArgs e)


{
Label1.Text = "Your Selected Date:" + Calendar1.SelectedDate.Date.ToString();
}
}
}

Aspx Code:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Register.aspx.cs"


Inherits="WebApplication1.Register" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<asp:Calendar ID="Calendar1" runat="server" BackColor="#FFFFCC"
BorderColor="#FFCC66" BorderWidth="1px" DayNameFormat="Shortest" Font-
Names="Verdana" Font-Size="8pt" ForeColor="#663399" Height="200px"
NextPrevFormat="ShortMonth" OnDayRender="Calendar1_DayRender"
ShowGridLines="True" Width="300px"
OnSelectionChanged="Calendar1_SelectionChanged" >
<DayHeaderStyle BackColor="#FFCC66" Font-Bold="True" Height="1px" />
<NextPrevStyle BorderStyle="Solid" BorderWidth="2px" Font-Size="9pt"
ForeColor="#FFFFCC" />
<OtherMonthDayStyle BackColor="#FFCC99" BorderStyle="Solid"
ForeColor="#CC9966" />
<SelectedDayStyle BackColor="Red" Font-Bold="True" />
<SelectorStyle BackColor="#FFCC66" />
<TitleStyle BackColor="#990000" Font-Bold="True" Font-Size="9pt"
ForeColor="#FFFFCC" />
<TodayDayStyle BackColor="#FFCC66" ForeColor="White" />
<WeekendDayStyle Height="50px" />
</asp:Calendar>
<br />
<br />
<asp:Label ID="Label1" runat="server"></asp:Label>
<br />
<asp:Label ID="Label2" runat="server"></asp:Label>
<br />
<asp:Label ID="Label3" runat="server"></asp:Label>
<br />
<asp:Label ID="Label4" runat="server"></asp:Label>
<br />
<asp:Label ID="Label5" runat="server"></asp:Label>
<br />
<br />
<asp:Button ID="Button1" runat="server" OnClick="btnResult_Click" Text="Result" -
<br />
<asp:Button ID="Button2" runat="server" OnClick="btnReset_Click" Text="Reset" />
</form>
</body>
</html>

You might also like