compute the side area, total area, and volume of a cylinder and the area and volume of a sphere, depending on the choice that the user makes. Your program should ask users to enter 1 to choose cylinder or 2 for sphere, and display an "invalid choice error" for other values.
compute the side area, total area, and volume of a cylinder and the area and volume of a sphere, depending on the choice that the user makes. Your
NOTE:--since programming language is not specified so we are providing solution in c programming.
#SOURCECODE
#include<stdio.h>
void main()
{
float sa,ta,vol,h,r,pi=3.14;
int n;
printf("enter the radius:");
scanf("%f",&r);
printf("enter the height:");
scanf("%f",&h);
printf("\nenter 1 for cylinder\nenter 2 for sphere");
printf("\nenter choice:");
scanf("%d",&n);
switch (n)
{
case 1:
sa=2*pi*r*h;
ta=sa+(2*pi*r*r);
vol=pi*r*r*h;
printf("side area of cylinder=%f",sa);
printf("\ntotal area of cylinder=%f",ta);
printf("\nvolume of cylinder=%f",vol);
break;
case 2:
sa=4*pi*r*r;
vol=(4/3)*pi*r*r*h;
printf("area of sphere%f",sa);
printf("\nvolume of sphere%f",vol);
break;
default:
printf("invalid choice error");
break;
}
}
OUTPUT:--
enter the radius:2.1
enter the hieght:5.0
enter 1 for cylinder
enter 2 for sphere
enter choice:1
side area of cylinder=65.940002
total area of cylinder=93.634796
volume of cylinder=69.236992
enter the radius:2.2
enter the hieght:3.5
enter 1 for cylinder
enter 2 for sphere
enter choice:2
area of sphere60.790405
volume of sphere53.191605
Step by step
Solved in 4 steps with 4 images