C Program with Algorithm to Find Volume of Sphere,Cone and Cylinder(using switch...case..default).



#include<stdio.h>
#include<conio.h>
#define pi 3.14
void main()
{
char x;
int i=1;
float r,h;
clrscr();
while(i)
{
printf("\n\tVolume Calculator\n\nSelect option\n\n1.Sphere\n\n2.Cone\n\n3.Cylinder\n\n4.Exit\n");
x=getch();
switch(x)
{
case '1':
printf("\n\tSphere\n\nEnter radious\t: ");
scanf("%f",&r);
printf("\nTotal Volume\t: %.2f\n",pi*r*r*r*4/3);
getch();
break;
case '2':
printf("\n\tCone\n\nEnter radious\t: ");
scanf("%f",&r);
printf("\nEnter Heigth\t: ");
scanf("%f",&h);
printf("\nTotal Volume\t: %f\n",pi*r*r*h*1/3);
getch();
break;
case '3':
printf("\n\tCylinder\nEnter radious\t: ");
scanf("%f",&r);
printf("\nEnter Heigth\t: ");
scanf("%f",&h);
printf("\nTotal Volume\t: %.2f\n",pi*r*r*h*4/3);
getch();
break;
case '4':
i=0;
break;
      default :
printf("\n%d is invalid\n",x);
}
}

}

Algorithm
step 1: Start
step 2: Define pi<-3.14
step 3: Intilize 1<-1
step 4: check whether i=1 then go to step5
else go to step 24
step 5: Read x
step 6: check whether x=1,then go to step 7
else go to step 10
step 7: Read r
step 8: print 4/3*pi*r*r*r
step 9: break
step 10: check whether x=2,then go to step 11
else go to step 14
step 11: read r and h
step 12: print 1/3*pi*r*r*h
step 13: break
step 14: check whether x=3,then go to step 15
else go to step 18
step 15: read r and h
step 16: print 4/3*pi*r*r*r
step 17: break
step 18: check whether x=4,then go to step 19
else go to step 21
step 19: i=0
step 20: break
step 21: print invalid
step 22: break
step 23: go to step 4
step 24: Stop