0% found this document useful (0 votes)
59 views6 pages

Lab 1

The document contains 12 C programming code examples that demonstrate how to: 1) Calculate the volume of a pool given its length, width, and depth 2) Print the sum, product, and quotient of two numbers 3) Calculate the surface area and volume of a sphere given its radius

Uploaded by

Avishek Rauniyar
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)
59 views6 pages

Lab 1

The document contains 12 C programming code examples that demonstrate how to: 1) Calculate the volume of a pool given its length, width, and depth 2) Print the sum, product, and quotient of two numbers 3) Calculate the surface area and volume of a sphere given its radius

Uploaded by

Avishek Rauniyar
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/ 6

1. Write a C Program to calculate the volume of a pool.

The equation for


determining the volume is Volume = length x width x depth. Assume that the
pool has a length of 25 feet, a width of 10 feet and depth 6 feet.

#include<stdio.h>
int main()
{
int l,w,d,v;
l=25;
w=10;
d=6;
v=l*w*d;
printf("The volume of the pool is %d ft^3",v);
return 0;
}

2. Write a program to print Sum, Product and Quotient of two numbers 22 and 7.

#include<stdio.h>
void main()
{
float a,b;
a=22;
b=7;
float q;
float s,p;
s=a+b;
p=a*b;
q = a/b;
printf("The sum is %f \n The product is %f \n The quotient is
%f",s,p,q);
}

3. Write a program to read the radius of sphere and compute its surface area and
volume.
#include<stdio.h>
int main()
{
float r,pi,as,v,b;
a=22;
b=7;
pi=a/b;
scanf("%f,&r);
s=4*pi*(r^2);
v=4*pi*(r^3);
printf(The surface area is %f \n The volume of sphere is
%f", s,v);
return 0;
}

4. Write a program to input temperature in Celsius & to print its Fahrenheit


equivalent. F = C * (9/5) + 32.

#include<stdio.h>
int main()
{
float c,f;
printf("Enter degree in celsius: ");
scanf("%f",&c);
f=c*(9/5)+32;
printf("The degree in fahrenheit scale is %f",f);
return 0;
}

5. Write a program to read base & altitude of a triangle & print its area:

#include<stdio.h>
int main()
{
float b,h,a,c;
printf("Enter base and height : ");
scanf("%f%f",&b,&h);
c=0.5;
a=c*b*h;
printf("The area of the triangle is %f",a);
return 0;
}
6. Write a program to calculate simple interest amount for deposit amount (P)
kept in bank for (n) years at the rate of ( r) simple interest per annum

#include<stdio.h>
int main()
{
float p,n,r,si;
printf("Enter p, t ,r ");
scanf("%f%f%f",&p,&n,&r);
si=(p*n*r)/100;
printf("The simple interest is %f",si);
return 0;
}

7. Write a program to input four numbers and print percentages of each numbers
on their sum.

#include<stdio.h>
int main()
{
float a, b, c, d, e, f, g, h, s;
printf("Enter four numbers : ");
scanf("%f%f%f%f",&a,&b,&c,&d);
s=a+b+c+d;
e=(a/s)*100;
f=(b/s)*100;
g=(c/s)*100;
h=(d/s)*100;
printf("The percentage of each numbers are %f %f %f %f
", e,f,g,h);
return 0;
}

8. Write a program to evaluate the expression (i) a + b (ii) a – b (iii) a x b (iv) a/b
(v) Remainder of a/b.

#include<stdio.h>
int main()
{
int a,b,s,d,m,q,r;
printf("Enter a and b");
scanf("%d%d",&a,&b);
s = a+b;
d = a-b;
m = a*b;
q =a/b;
r= a%b;
printf("The sum is %d \n The difference is %d \n The
product is %d \n The quotient is %d \n The reminder is
%d",s,d,m,q,r);

return 0;
}

9. Write a program to input 2-digit integer number and print sum of digits in it.

#include<stdio.h>
int main()
{
int a,d;
printf("Enter a two digit number");
scanf("%d",&a);
d=a % 10;
a=(a-d)/10;
a=a+d;
printf("The sum of digits is %d",a);
return 0;
}

10.Given a 2-digit integer number. Write a program to print it in reverse order


(e.g. 92 ⇒ 29)

#include<stdio.h>
int main()
{
int a,d;
printf("Enter a two digit number ");
scanf("%d",&a);
d=a % 10;
a=(a-d)/10;
a=d*10+a;
printf("The reverse of digits is %d",a);
return 0;
}

11.Write a program to compute:

F=(2.9678 x 10-27 + 0.876 x 10-38 )/( 7.025 x 1016 – 9.75 x 10 12)

#include<stdio.h>
int main()
{
double e,g,f,a,b,c,d;
a= 2.9678*(10^(-27));
b=0.876*(10^(-38));
c=7.025*(10^16);
d=9.75*(10^12);
e=a+b;
g=c-d;
f=e/g;
printf("The output is %E",f);
return 0;
}

12. Write a C program to prompt the user for the x- and y-coordinates of the three
corners of a triangle, calculate and print the lengths of the three sides,
calculate and print the circumference of the triangle, and calculate and print
the area of the triangle. The following mathematical formulas may be used in
these calculations: –
The formula for determining the length lAB of the line between points (xA,
yA) and (xB, yB) is

lAB = ((xA −xB )2 +( yA − yB )2 .)1/2

If lAB, lBC, and lCA are the lengths of the three sides of a triangle, then the
area of the triangle is
(s × (s−lAB ) × (s−lBC ) × (s−lCA))1/2

where s is one-half the circumference of the triangle – i.e., s = ½ × (lAB +


lBC + lCA).

#include<stdio.h>
#include<math.h>
int main()
{
printf("Enter x and y coordinates of three sides of a
triangle ");
int a,b,c,d,e,f,g,h,i,j,k,l;
scanf("%d%d%d%d%d%d", &a,&b,&c,&d,&e,&f);
g=pow((pow((a-c),2))+(pow((b-d),2)),(1/2));
h=pow((pow((e-c),2))+(pow((f-d),2)),(1/2));
i=pow((pow((a-e),2))+(pow((b-f),2)),(1/2));
k=g+h+i;
j=pow(k,(1/2));
l=pow((j*(j-g)*(j-h)*(j-i)),(1/2));
printf("The lengths of three sides are %d %d %d \n The
circumference of the triangle is %d \n The area of the triangle is
%d", g,h,i,k,l);
return 0;
}

You might also like