The length & breadth of a rectangle and radius of a circle are input through the keyboard. Write a program to calculate the area & perimeter of the rectangle, and the area & circumference of the circle.
void main()
{
float l,b,r,arear,perimeterr,areac,perimeterc;
printf("\nInput the length and breadth of rectangle and radius of circle respectively");
scanf("%f%f%f",&l,&b,&r);
arear=l*b;
perimeterr=2*l+2*b;
areac=3.141592654*r*r;
perimeterc=2*3.141592654*r;
printf("\nThe area of rectangle is %f\nThe perimeter of rectangle is %f\nThe area of circle is %f\nThe circumference of the circle is %f",arear,perimeterr,areac,perimeterc);
}
Saturday, January 30, 2010
CHAP 1[H]d Converting Fahrenheit to Centigrade degrees
Temperature of a city in Fahrenheit degrees is input through the keyboard. Write a program to convert this temperature into Centigrade degrees.
void main()
{
float c,f;
printf("\nInput the temperate(Fahrenheit)");
scanf("%f",&f);
c= (f-32)*(100.0/180.0);
printf("\nThe temperature in Celsius is %f",c);
}
void main()
{
float c,f;
printf("\nInput the temperate(Fahrenheit)");
scanf("%f",&f);
c= (f-32)*(100.0/180.0);
printf("\nThe temperature in Celsius is %f",c);
}
CHAP 1[H]c Finding aggregate and percentage marks
If the marks obtained by a student in five different subjects are input through the keyboard, find out the aggregate marks and percentage marks obtained by the student. Assume that the maximum marks that can be obtained by a student in each subject is 100.
void main()
{
float a,b,c,d,e,t,am,pm;
printf("\nInput the 5 test marks followed by total obtainable marks");
scanf("%f%f%f%f%f%f",&a,&b,&c,&d,&e,&t);
am=(a+b+c+d+e)/5;
pm=(am/t)*100.0;
printf("\nThe aggregate marks is %f\nThe percentage marks is %f",am,pm);
}
void main()
{
float a,b,c,d,e,t,am,pm;
printf("\nInput the 5 test marks followed by total obtainable marks");
scanf("%f%f%f%f%f%f",&a,&b,&c,&d,&e,&t);
am=(a+b+c+d+e)/5;
pm=(am/t)*100.0;
printf("\nThe aggregate marks is %f\nThe percentage marks is %f",am,pm);
}
CHAP 1[H]b Converting distance in km to m,inches,cm
The distance between two cities (in km.) is input through the keyboard. Write a program to convert and print this distance in meters, feet, inches and centimeters.
void main()
{
float distance,distancem,distancefeet,distanceinches,distancecm;
printf("\nInput distance in km");
scanf("%f",&distance);
distancem= distance*1000.0;
distancefeet= distancem*3.2808;
distanceinches= (distance*100000.0)/2.54;
distancecm = distance*100000.0;
printf("\n Distance in metres = %fm\n Distance in feet = %fft\n Distance in inches = %finches\n Distance in cm = %fcm",distancem,distancefeet,distanceinches,distancecm);
}
void main()
{
float distance,distancem,distancefeet,distanceinches,distancecm;
printf("\nInput distance in km");
scanf("%f",&distance);
distancem= distance*1000.0;
distancefeet= distancem*3.2808;
distanceinches= (distance*100000.0)/2.54;
distancecm = distance*100000.0;
printf("\n Distance in metres = %fm\n Distance in feet = %fft\n Distance in inches = %finches\n Distance in cm = %fcm",distancem,distancefeet,distanceinches,distancecm);
}
CHAP 1[H]a Calculating gross salary
Ramesh’s basic salary is input through the keyboard. His dearness allowance is 40% of basic salary, and house rent allowance is 20% of basic salary. Write a program to calculate his gross salary.
void main()
{
float bs,gs;
printf("\nInput Basic Salary");
scanf("%f",&bs);
gs=bs*(16.0/10.0);
printf("\nGross Salary is %f",gs);
}
void main()
{
float bs,gs;
printf("\nInput Basic Salary");
scanf("%f",&bs);
gs=bs*(16.0/10.0);
printf("\nGross Salary is %f",gs);
}
CHAP 2[C]L Checking if coordinate lies on,x,y axis or on origin
Given a point (x, y), write a program to find out if it lies on the x-axis, y-axis or at the origin, viz. (0, 0).
void main()
{
float x,y;
printf("\nInput the(x,y) values");
scanf("%f%f",&x,&y);
if(x==0&&y==0)
printf("\nThe point lies on the origin");
else if(x==0&&y!=0)
printf("\nThe point lies on the y-axis");
else if(x!=0&&y==0)
printf("\nThe point lies on the x-axis");
else
printf("\nThe point does not lie on any axis or origin");
}
void main()
{
float x,y;
printf("\nInput the(x,y) values");
scanf("%f%f",&x,&y);
if(x==0&&y==0)
printf("\nThe point lies on the origin");
else if(x==0&&y!=0)
printf("\nThe point lies on the y-axis");
else if(x!=0&&y==0)
printf("\nThe point lies on the x-axis");
else
printf("\nThe point does not lie on any axis or origin");
}
CHAP 2[C]j Checking if three coordinates form a straight line
Given three points (x1, y1), (x2, y2) and (x3, y3), write a program to check if all the three points fall on one straight line.
void main()
{
float x1,x2,x3,y1,y2,y3;
printf("\nEnter the three coordinates (x1,y1),(x2,y2),(x3,y3)");
scanf("%f%f%f%f%f%f",&x1,&y1,&x2,&y2,&x3,&y3);
if ((y2-y1)/(x2-x1)==(y3-y2)/(x3-x2))
printf("\nThe three points fall on the same line");
else
printf("\nThe three points are not collinear");
}
void main()
{
float x1,x2,x3,y1,y2,y3;
printf("\nEnter the three coordinates (x1,y1),(x2,y2),(x3,y3)");
scanf("%f%f%f%f%f%f",&x1,&y1,&x2,&y2,&x3,&y3);
if ((y2-y1)/(x2-x1)==(y3-y2)/(x3-x2))
printf("\nThe three points fall on the same line");
else
printf("\nThe three points are not collinear");
}
Subscribe to:
Posts (Atom)