Tuesday, December 22, 2009

/*Program to Display Hello World!*/
#include
#include
void main()
{
clrscr();
printf("Hello World!");
getch();
}
/*Program to calcualte sum of two numbers*/
#include
#include
void main()
{
int a =5 , b=10, c;
clrscr();
c=a+b;
printf("Sum of a & b is = %d",c);
getch();
}
/*Program to calcualte product & difference between two numbers*/
#include
#include
void main()
{
int a,b,c,d;
clrscr();
printf("Enter any number");
scanf("%d",&a);
printf("Enter another number");
scanf("%d",&b);
c=a*b;
d=a-b;
printf("Product is = %d",c);
printf("\nDifference is = %d",d);
getch();
}
/*Program to calculate Simple Interest*/
#include
#include
void main()
{
float p,r,t,si;
clrscr();
printf("Enter Principal");
scanf("%f",&p);
printf("Enter Rate");
scanf("%f",&r);
printf("Enter Time");
scanf("%f",&t);
si=(p*r*t)/100;
printf("Simple Interest is = %f",si);
getch();
}
/*Program to swap two numbers without using any variable*/
#include
#include
void main()
{
int a,b;
clrscr();
printf("Enter any two numbers");
scanf("%d,%d",&a,&b);
a=a+b;
b=a-b;
a=a-b;
printf("Value after swapping is = %d, %d",a,b);
getch();
}
/*Program to swap two numbers using third variable*/
#include
#include
void main()
{
int a,b,c;
clrscr();
printf("Enter any two numbers");
scanf("%d,%d",&a,&b);
c=a;
a=b;
b=c;
printf("Value of a & b after swapping is : %d, %d",a,b);
getch();
}
/* Program to make use of different data types in'C'*/
#include
#include
void main()
{
float x,p;
double y,q;
unsigned int k;
int m=54321;
long int n = 1234567890;
x=1.23456789000;
y=9.87654321;
k=54321;
p=q=1.0;
printf("m=%d\n",m);
printf("n=%ld\n",n);
printf("x=12lf\n",x);
printf("x=%f\n",x);
printf("y=12%lf\n",y);
printf("y=%f\n",y);
printf("k=%u p=%f q=%.12lf\n",k,p,q);
getch();
}
/* Program to make use of formatting output*/
#include
#include
void main()
{
int year,period;
float amount,inrate,value;
clrscr();
printf("Enter Amount,Interest Rate and period\n\n");
scanf("%f,%f,%d",&amount,&inrate,&period);
printf("\n");
year=1;
while(year<=period)
{
value=amount+inrate+amount;
printf("%2d Rs. %8.2f\n",year,value);
amount=value;
year=year+1;
}
getch();
}
/* program using different operators of 'C'*/
#include
#include
void main()
{
int a,b,c,d;
clrscr();
a = 15; b = 10;
c = ++a - b;
printf("a=%d b=%d c=%d\n",a,b,c);
d=b++ +a;
printf("a=%d b=%d d=%d\n",a,b,d);
printf("a/b=%d\n",a/b);
printf("a%%d=%d\n",a%d);
printf("a*=b=%d\n",a*=b);
printf("%d\n",(c>d)?1:0);
printf("%d\n",(cgetch();
}
/* Program to understand operators precedence*/
#include
#include
void main()
{
float a,b,c,x,y,z;
clrscr();
a=9; b=12; c=3;
x=a-b/3+c*2-1;
y=a-b/(3+c)*(2-1);
z=a-(b/(3+c)*2)-1;
printf("x=%f\n",x);
printf("y=%f\n",y);
printf("z=%f\n",z);
getch();
}

No comments:

Post a Comment