Simple Console applications
Even Number
using System;
class First
{
static void Main()
{
Console.WriteLine("Even no's between 1 to 100"); for(byte Number=1;Number<=100;Number++)
{
if(Number % 2==0)
{
Console.WriteLine("{0}",Number); } }
}
}
Area of a Circle
using System;
public class Second
{
public static void Main()
{
ulong Radius;
Second ob=new Second();
Console.WriteLine("enter the Radius of circle");
Radius=ulong.Parse(Console.ReadLine());
ob.Areac(Radius);
ulong Basex;
ulong Height;
Console.WriteLine("enter the Base of triangle");
Basex =ulong.Parse(Console.ReadLine());
Console.WriteLine("enter the Radius of circle");
Height=ulong.Parse(Console.ReadLine());
ob.Areat(Basex,Height);
}
void Areac(ulong x)
{
ulong Area= (ulong)(3.14 * (x)*x);
Console.WriteLine("Area of circle is {0}",Area); }
void Areat(ulong x,ulong y)
{ ulong AreaofT=(ulong)((0.5)*x*y) ;
Console.Write("the area of triangle is");
Console.WriteLine ("{0}",AreaofT);
}
}
Exponential
using System;
class Exponential
{
static void Main(string[] args)
{
Exponential ob=new Exponential();
Decimal x,eX=0,term;
Console.WriteLine("enter the value of x");
x = Decimal.Parse(Console.ReadLine());
for(int i=0;i<=31;i++)
{
term= (ob.power (i,x)/ob.factorial (i));
eX = eX + term;
}
Console .WriteLine ("The value of eX is {0}",eX);
}
public int factorial(int n)
{
int Fact = 1;
for (int i = 1; i <= n; i++)
{
Fact = Fact * i;
}
return Fact;
}
public decimal power(int n,decimal x)
{
decimal val=1;
if (n==0)
{ val=1;
}
for(int i=1;i<=n;i++)
{
val=val*x;
}
return val ;
}
}
Sum Average Percentage of 5 No
using System;
class Fivesub
{
static void Main(string[] args)
{
int Sub1, Sub2, Sub3, Sub4, Sub5;
Console.WriteLine ("enter the 1st subject marks");
Sub1=int.Parse (Console .ReadLine ());
Console.WriteLine ("enter the 2nd subject marks");
Sub2=int.Parse (Console .ReadLine ());
Console.WriteLine ("enter the 3rd subject marks");
Sub3=int.Parse (Console .ReadLine ());
Console.WriteLine ("enter the 4rth subject marks");
Sub4=int.Parse (Console .ReadLine ());
Console.WriteLine ("enter the 5th subject marks");
Sub5=int.Parse (Console .ReadLine ());
int Sum = Sub1 + Sub2 + Sub3 + Sub4 + Sub5;
float Avg;
Avg = (float)(Sum / 5.0);
float Percentage =(float) ((Sum / 5.0));
Console.WriteLine("Sum of marks is {0}", Sum);
Console.WriteLine("Average marks is {0}", Avg );
Console.WriteLine("Total Percentage is {0}%",Percentage );
}
}
Leap year or Not
using System;
class Second
{
public static void Main()
{short year;
Console.WriteLine("enter the year");
year=short.Parse(Console.ReadLine());
if(year % 4==0)
{
Console.WriteLine("year is leap year");
}
else{
Console.WriteLine("year is not a leap year");
}
}
}
Maximum of three
using System;
class Maxofthree
{
static void Main(string[] args)
{
int n1, n2, n3;
Console .WriteLine ("enter the n1");
n1 = int.Parse(Console.ReadLine());
Console .WriteLine ("enter the n2");
n2 = int.Parse(Console .ReadLine ());
Console .WriteLine ("enter the n3");
n3=int.Parse (Console .ReadLine ());
int max=(n1>n2 &&n1>n3)?n1:((n2>n1 && n2>n3)?n2:((n3>n1 && n3>n1)?n3:0 ));
if (max != 0)
{
Console.WriteLine("The max of three is {0}", max);
}
else
{
Console.WriteLine("all are equal");
}
}
}
Compute nCr
using System;
class NCR
{
static void Main(string[] args)
{
int n,r,ncr;
Console.WriteLine("enter n");
n = int.Parse(Console.ReadLine());
Console.WriteLine("enter r");
r = int.Parse(Console.ReadLine());
NCR ob=new NCR();
ncr = ((ob.factorial(n)) / (ob.factorial(r) * ob.factorial(n - r)));
Console.WriteLine("The value of Ncr is {0}", ncr);
}
public int factorial(int n)
{
int Fact = 1;
for (int i = 1; i <= n; i++)
{
Fact = Fact * i;
}
return Fact;
}
}
Print Table of a Number
using System;
class Printtable
{
static void Main(string[] args)
{
int number;
Console.WriteLine("enter the number");
number = int.Parse(Console.ReadLine());
for (int i = 1; i <= 10; i++)
{
int val = number * i;
Console.WriteLine("{0} x {1}={2}", number, i, val);
}
}
}
Convert Fahrenheit to Celsius and Celsius to Fahrenheit
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
float Fht;
float Cel;
Console.WriteLine("Enter your choice");
A : Console.WriteLine ("Enter 1-for Fehrenhiet to celsius and 2-for Celsius to fehrenhiet");
int ch = int.Parse(Console.ReadLine());
switch (ch)
{
case 1:
Console.WriteLine ("enter the temperature in fehrehiet");
Fht =int.Parse((Console.ReadLine()));
Cel=((5/9)*(Fht-32)) ;
Console.WriteLine ("The temperature in celsius is {0}",Cel);
break;
case 2:
Console.WriteLine ("enter the temperature in celsius");
Cel =int.Parse (Console.ReadLine());
Fht=(((9/5)*Cel) + 32) ;
Console.WriteLine ("The temperature in Fehrenhiet is {0}",Fht);
break;
default :
Console.WriteLine ("Wrong choice selection re-enter the choice");
goto A;
}
}
}
}
Reverse the Order of a number
using System;
class Second
{
public static void Main()
{
int No;
int sum=0;
Console.WriteLine("enter the number");
No=(int.Parse)(Console.ReadLine());
Console.WriteLine("Number in reverse order");
while(No>0)
{
int x=No%10;
No=No/10 ;
sum=sum+No;
Console.Write ("{0}",x);
}
}
}
Calculate Sum of digits of a number
using System;
class Second
{
public static void Main()
{
int No;
int sum=0;
Console.WriteLine("enter the number");
No=(int.Parse)(Console.ReadLine());
while(No>0)
{
int x=No%10;
No=No/10 ;
sum=sum+x;
}
Console.Write ("{0}",sum);
}
}
Swap Numbers
using System;
class Second
{
public static void Main()
{int no1;
int no2;
Console.WriteLine("enter the ist no");
no1=int.Parse(Console.ReadLine());
Console.WriteLine("enter the 2nd no");
no2=int.Parse(Console.ReadLine());
no1=no1-no2;
no2=no1+no2;
no1=no2-no1;
Console.WriteLine("The nos are:{0}and{1}",no1,no2);
}
}
Convert String to Upper without Using Direct Function
using System;
class Upperstring
{
static void Main(string[] args)
{
Console.WriteLine("Enter the lowercase character");
char chr=char.Parse (Console.ReadLine());
int val=(int)(chr);
val=val-32;
chr=(char)(val);
Console.WriteLine("uppercase character is {0}",chr);
}
}

No comments:
Post a Comment