Basic PRG
Basic PRG
void is the return type of the method. It means it doesn't return any value.
string[] args is used for command line argument. We will discuss it in coming
section.
namespace System
|
classes Console
|
methods()/function() WriteLine() /ReadLine()(static)
|
object
class HelloWorld
{
public static void Main(string[] args)
{
Console.WriteLine("Welcome to C# language");//printf cout
}
}
2.1)Substraction of 2 numbers
2.2)Division of 2 numbers
2.3)Multiplication of 2 numbers
3)Addition of 5 numbers
using System;
public class HelloWorld
{
public static void Main(string[] args)
{
int a=12134,b=14567,c=67,d=234,e=674,f;
f=a+b+c+d+e;
Console.WriteLine("Addition ={0} ",f);
}
}
4)Multiplication of 4 numbers
2)Substraction of 2 no
3)Multiplication of 2 no
4)Division
5)Addition of 5 no
using System;
public class Add5
{
public static void Main(string[] args)
{
int a,b,c,d,e,f;
Console.WriteLine("Enter 5 no");//printf
a=Convert.ToInt32(Console.ReadLine());//scanf
b=Convert.ToInt32(Console.ReadLine());
c=Convert.ToInt32(Console.ReadLine());
d=Convert.ToInt32(Console.ReadLine());
e=Convert.ToInt32(Console.ReadLine());
f=a+b+c+d+e;
Console.WriteLine("Addition={0}",f);
}
}
6)Addition of 7 no
7)Multiplication of 4 numbers.
1)Area of circle
A=3.14*r*r;
i/p r
o/p A
using System;
2)Area of rectangle
A=l*b
i/p l,b
o/p A
3)Area of triangle
A=0.5*b*h
i/p b,h
o/p A
4)
pe=m*g*h
i/p m,g,h
o/p pe
5)
ke=0.5*m*v*v
i/p m,v
o/p ke
6)
Arithmetic mean & Harmonic mean
am=(a+b)/2
hm=(a-b)/2
i/p a,b
o/p am,hm
using System;
13)
Accept basic salary from user & calculate HRA(home rental allowance),TA(travelling
Allowance),
DA(Dinner allowance) & GS(gross salary)
i/p bs
o/p
hra
ta
da
tax
gs
hra=50% on bs hra=bs*0.50;
ta=40% on bs ta=bs*0.40;
da=60% on bs da=bs*0.60
tax=5% on bs tax=bs*0.05
gs=(bs+hra+ta+da)-tax;
using System;
public class GS
{
public static void Main(string[] args)
{
double bs,hra,ta,da,tax,gs;
Console.WriteLine("Enter bs");//printf
bs=Convert.ToDouble(Console.ReadLine());//scanf
hra=bs*0.50;
ta=bs*0.40;
da=bs*0.60;
tax=bs*0.05;
gs=(bs+hra+ta+da)-tax;
Console.WriteLine("HRA={0}\nTA={1}\nDA={2}\nTAx={3}\
nGS={4}",hra,ta,da,tax,gs);
}
}
14)
room l,b,h 2*(l*b + l*h + b*h)
door l1,h1
window l2,h2(2 window)
calculate total area with roof is painted
using System;
Console.WriteLine("Area={0}",area);
}
}
logic
a=b;//a=200
b=a;//b=200 wrong
using System;
class HelloWorld {
static void Main()
{
int a,b,c;
Console.WriteLine("Enter 2 no");//printf
a=Convert.ToInt32(Console.ReadLine());//scanf
b=Convert.ToInt32(Console.ReadLine());
Console.WriteLine("\nBefore Swapping\n A={0} B={1}",a,b);
c=a;//a=100 b=200 c=100
a=b;//a=200
b=c;//b=100
Console.WriteLine("\nAfter Swapping\n A={0} B={1}",a,b);
}
}
17)
i/p h,m,s
o/p seconds
1hr=3600
1min=60
using System;
class HelloWorld {
static void Main()
{
int h,m,s,sec;
Console.WriteLine("Enter H,M,S");
h=Convert.ToInt32(Console.ReadLine());
m=Convert.ToInt32(Console.ReadLine());
s=Convert.ToInt32(Console.ReadLine());
sec=(h*3600)+(m*60)+s;
Console.WriteLine("sec={0}",sec);
}
}
18)
i/p km
o/p m
m=km*1000;
19)
i/p liter
o/p ml
ml=liter*1000;
20)
i/p
meter 2750
o/p km
{
int meter,km;
21)
i/p ml
o/p liter
/=quotient 17/3=5
%=reMainder 17%3=2
7530/3600=2
7530%3600=330
330/60=5
330%60=30
using System;
i/p 8888
o/p
2000*4=8000 CW("2000 * {0} ={1} ",twot,(2000*towt));
500*1=500
200*1=200
100*1=100
50*1=50
20*1=20
10*1=10
5*1=5
2*1=2
1*1=1
______________
total=8888
8888/2000=4
8888%2000=888
888/500=1
888%500=388
388/200=1
388%200=188
.
.
.
.
using System;