Lab 1
Lab 1
#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;
}
#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;
}
#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;
}
#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
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
#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;
}