Friday, 4 December 2015

Menu Driven Program To Find Volume Of Sphere And Cube

AIM
To write a menu driven program for finding the volume of a sphere and a cube
ALGORITHM
Step 1:   Start
Step 2:   Print choice sphere ,cube
Step 3:   if cube go to  step 7
Step 4:   read radius r
Step 5:   vr*r*r*(4/3)*3.14
Step 6:   Print v
Step 7:   read side s
Step 8:   vs*s*s
Step 9: print v
Step 10: print want to continue?
Step 11: if yes,go to step 1
Step 12: stop

PROGRAM
#include<stdio.h>
#include<conio.h>
void main()
{
    char t,y,Y,n;
    float radius,side,pi;
    int ch;
    pi=3.14;
     do

   {
    printf("\nMENU\n1)volume of sphere\n2)volume of cube\n");
    scanf("%d",&ch);
    switch (ch)
    {
        case 1:
        printf("Enter the value of radius\n");
        scanf("%f",&radius);
        printf("the volume of the sphere=%f cm3",radius*radius*radius*pi*(1.33));
        break;
        case 2:
        printf("\nEnter the value of side\n");
        scanf("%f",&side);
        printf("the volume of the cube=%f cm3",side*side);
        break;
        default:printf("INVALID CHOICE");
        break;
    }
        printf("\n\nDO YOU WANT TO CONTINUE:\nThen press y else n:");
        fflush(stdin);
        scanf("%c",&t);
   }
        while(t=='y'||t=='Y');
        getch();
}
RESULT
The menu driven program for finding the volume of sphere and cube was written , executed and the output  verified successfully.


OUTPUT
Menu Driven Program To Find Volume Of  Sphere  And Cube

No comments:

Post a Comment