Computer Science, asked by hsidhu7724, 1 year ago

Write a program using switch case to find the volume of a cube a sphere and a cuboid. For an incorrect choice an appropriate error message should be displayed. a. Volume of the cube =s*s*s b.Volume of the sphere=4/3*3.14*r*r*r c. Volume of the cuboid=l*b*h

Answers

Answered by GoshtHunter
27
C program (menu driven) to find the volume and surface area of cube,
cuboids, cylinder, cone, sphere and hemi-sphere

#include <stdio.h>
#include<conio.h>
#include <stdlib.h>
#include <math.h>
  int main() {
    float v,sa;
    int a,l,b,h,ch,r,s;
    clrscr();
    while(1) {
        /* get the option from user */
        printf("1. Cube\t2. Cuboid\n");
        printf("3. Cylinder\t4. Cone\n");
        printf("5. Sphere\t6. Hemi-sphere\n");
        printf("7. Exit\n");

        printf("Enter your choice:");
        scanf("%d", &ch);
        switch(ch) {
            case 1:
                printf("Enter the value of a for cube:");
                scanf("%d", &a);
                v=a*a*a;
                sa=6*a*a*a*a*a*a;
        printf("Surface Area of Cube: %f\n", sa);
        printf("\nVolumn of Cube: %f\n",v);
                break;

            case 2:
        printf("\nEnter the value of l,h and b for cuboid:");
        scanf("%d%d%d",&l,&h,&b);
                v=l*h*b;
                sa=(2*l*h)+(2*h*b)+(2*b*l);
        printf("Surface Area of Cuboid: %f\n", sa);
        printf("\nVolumn of Cuboid: %f\n",v);

                break;

            case 3:
        printf("\nEnter the value of r and h for Cylinder:");
        scanf("%d%d",&r,&h);
                v=3.14*r*r*h;
                sa=(2*3.14*r*r)+(2*3.14*r*h);
        printf("Surface Area of Cylinder: %f\n", sa);
        printf("\nVolumn of Cylinder: %f\n",v);

                break;


            case 4:
        printf("\nEnter the value of r, h and s for Cone:");
        scanf("%d%d%d",&r,&h);
                v=(1/3)*3.14*r*r*h;
                sa=(3.14*r*s)+(3.14*r*r);
        printf("Surface Area of Cone: %f\n", sa);
        printf("\nVolumn of Cone: %f\n",v);

                break;


            case 5:
        printf("\nEnter the value of r for Sphere:");
        scanf("%d%d",&r,&h);
                v=(4/3)*3.14*r*r*r;
                sa=4*3.14*r*r;
        printf("Surface Area of Sphere: %f\n", sa);
        printf("Volumn of Sphere: %f\n",v);

                break;


            case 6:

        printf("\nEnter the value of r for Hemi-Sphere:");
        scanf("%d%d",&r,&h);
                v=(2/3)*3.14*r*r*r;
                sa=2*3.14*r*r;
        printf("Surface Area of Hemi-Sphere: %f\n", sa);
        printf("Volumn of Hemi-Sphere: %f\n",v);

                break;


            case 7:
                exit(0);

            default:
                printf("Wrong OPTION IS BEEN ENTER!!\n");
                break;
         }
         getch();
         return 0;
    }


  }

OUTPURT:
     
       1. Cube     2. Cuboid
       3. Cylinder 4. Cone
       5. Sphere   6. Hemi-sphere
       7. Exit

       Enter your choice: 5
       Enter the value for r for Sphere: 6 5
       Surface Area of Sphere: 452.160004
       Volume of Sphere: 678.239990
Similar questions