#include <stdio.h>
#include <stdlib.h>
int main()
{
float length,width,height,box,radius,sphere,bt,ht,htp,prism,rc,hc,cylinder; char vol;
printf("Enter (b for box, s for sphere, p for prism, c for cylinder): ");
scanf("%c",&vol);
if (vol=='b')
{ /*For box*/
printf("Enter Length: ");
scanf("%f",&length);
printf("Enter Width: ");
scanf("%f",&width);
printf("Enter height: ");
scanf("%f",&height);
box=length*width*height; /*Volume of box=l*w*h.*/
printf("Volume of box is: %f",box);
}
else if(vol=='s')
/*For sphere*/
{printf("Enter Radius: ");
scanf("%f",&radius);
sphere=1.33*3.14*(radius*radius*radius); /*volum of sphere =4/3*pi*r3*/
printf("Volume of sphere: %f",sphere);
}
else if(vol=='p')
{ /*For prism*/
printf("Enter length of the base of the triangle: ");
scanf("%d",&bt);
printf("Enter height of the triangle: ");
scanf("%d",&ht);
printf("Enter height of the triangular prism: ");
scanf("%d",&htp);
prism=(0.5*bt*ht)*htp; /*1/2*b*h*H*/
printf("Volume of prism: %f",prism);
}
else if (vol=='c')
{ /*for cylinder*/
printf("Enter radius of the circle of the base: ");
scanf("%d",&rc);
printf("Enter height of the cylinder: ");
scanf("%d",&hc);
cylinder=3.14*(rc*rc)*hc; /*pi*r2*H*/
printf("Volume of cylinder: %d",cylinder); }
return 0;
getch();
}
No comments:
Post a Comment