Q:

C Program For Find Radius, Circumference and Volume of Cylinder Using Switch Case

belongs to collection: Switch Case Basic C Programs List

0

C Program For Find Radius, Circumference or Circle and Volume of Cylinder Using Switch Case or c program to find volume of cylinder or c program to find circumference of circle or c program to find area of circle or C Program For Find Radius, Circumference and Volume of Cylinder Using Switch Case or C Program For Find Radius, Circumference, and Volume of Cylinder Using Do while loop or C Program For Find Radius, Circumference, and Volume of Cylinder Using loop or C Program For Find Radius, Circumference or Circle and Volume of Cylinder Using do while loop.

 

Logic:

As we can see that we have to only apply the formula of area of circle or circumference of circle and volume of the cylinder and print the output on the screen, but we also have to put the condition in switch case so that users can easily choose their choice and perform an appropriate operation. In this problem PI value is fixed Pi value up to 10 decimal numbers PI = 3.1415926535.  See the below formulas and explanation of the problem so you can easily understand the problem.

Formula's Are using in problem
1. Area of Circle = PI * Radius * Radius
2. Circumference of Circle = 2 * PI * Radius
3. Volume of Cylinder = PI * Hight * Radius * Radius


Explanation:

In case 1 put the area of circle condition or in case 2 put the second condition Circumference of Circle and last but not least third condition put in case 3 Volume of Circle and now come to special condition case 4 if user want to quite then press 4 this will help to move out the user to loop. In case of the section, there is a special or default case help to check whether the user input the right input or not, if the user enters the input 5 then default case execute and print wrong input try again message on the console screen.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

#include<stdio.h>
#include<conio.h>

int main()
{
float radius=0.0,height=0.0;
char quit;
int choice;
const float pi=3.1415658;

do
{
printf("\n======================================="); 
printf("\nWhat Do You Want To Calculate?");
printf("\n1. For Area of Circle");
printf("\n2. For Circumference of Circle");
printf("\n3. For Volume of Cylinder");
printf("\n0. For For Quit");
printf("\n=======================================\n");
printf("\nEnter Your Choice Here:");
scanf("%d",&choice);

switch (choice)
{
case 1:
 printf("\nEnter Radius of Circle:");
 scanf("%f",&radius);
 printf("\n=======================================");
    printf("\nArea of Circle = %.5f",radius*radius*pi);
    printf("\n=======================================");
   break;
case 2:
 printf("\nEnter Radius of Circle:");
 scanf("%f",&radius);
 printf("=======================================");
    printf("\nCircumference of Circle = %.5f",2*radius*pi);
 printf("\n=======================================");
    break;
case 3:
 printf("\nEnter Radius of Cylinder:");
 scanf("%f",&radius);
    printf("\nEnter Hight of Cylinder:");
    scanf("%f",&height);
    printf("\n=======================================");
    printf("\nVolume of cylinder = %.5f",radius*radius*pi*height);
    printf("\n=======================================");
    break;
case 0:
    quit='y';
    break;
default:
 printf("\n=======================================");
    printf("\nWrong Choice....Try Again!!!\n");
    printf("=======================================");
   break;
}
}while(quit != 'y');

return 0;
}

 

Output:

=======================================

What Do You Want To Calculate?

1. For Area of Circle

2. For Circumference of Circle

3. For Volume of Cylinder

0. For For Quit

=======================================

Enter Your Choice Here:2

Enter Radius of Circle:10

=======================================

Circumference of Circle = 62.83131

=======================================

=======================================

What Do You Want To Calculate?

1. For Area of Circle

2. For Circumference of Circle

3. For Volume of Cylinder

0. For For Quit

=======================================

Enter Your Choice Here:3

Enter Radius of Cylinder:10

Enter Hight of Cylinder:5

=======================================

Volume of cylinder = 1570.78296

=======================================

=======================================

What Do You Want To Calculate?

1. For Area of Circle

2. For Circumference of Circle

3. For Volume of Cylinder

0. For For Quit

Enter Your Choice Here:

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

C Program To Delete (Remove) Vowels From A String ... >>
<< C Program to Find Grade of a Student Using Switch ...