Computer Science, asked by debotraya655, 8 months 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.
1. Volume of a cube = s * s *s
2. Volume of a sphere = (4/3) * π * r * r * r (π = (22/7))
3. Volume of a cuboid = l*b*h

Answers

Answered by pavithranatarajan855
4

Answer:

#include <stdio.h>

int main()

{

   int choice;

   float volume,pi=3.14;

   printf("\n1.cube \n2.sphere \n3.cuboid ");

   printf("\nEnter your choice");

   scanf("%d",&choice);

   switch(choice){

       case 1:

           printf("your choice is cube");

           int s;

           scanf("%d",&s);

           volume=s*s*s;

           break;

       case 2:

            printf("your choice is sphere");

            int r;

            scanf("%d",&r);

            volume=(4/3)*pi*r*r*r;

            break;

       case 3:

            printf("your choice is cuboid");

            int l,b,h;

            scanf("%d",&l);

            scanf("%d",&b);

            scanf("%d",&h);

            volume=l*b*h;

            break;

       default:

           printf("\nWrong input");

       

   }

   printf("volume=%f",volume);

   return 0;

}

Explanation:

Similar questions