Prerequisite : Switch Case in C
Problem Statement:
Write a menu-driven program using Switch case to calculate the following:
1. Area of circle
2. Area of square
3. Area of sphere
Also use functions input() and output() to input and display respective values.
// C program to illustrate // Menu-Driven program // using Switch-case #include <stdio.h> int input(); void output(float); int main() { float result; int choice, num; printf("Press 1 to calculate area of circle\n"); printf("Press 2 to calculate area of square\n"); printf("Press 3 to calculate area of sphere\n"); printf("Enter your choice:\n"); choice = input(); switch (choice) { case 1: { printf("Enter radius:\n"); num = input(); result = 3.14 * num * num; printf("Area of sphere="); output(result); break; } case 2: { printf("Enter side of square:\n"); num = input(); result = num * num; printf("Area of square="); output(result); break; } case 3: { printf("Enter radius:\n"); num = input(); result = 4 * (3.14 * num * num); printf("Area of sphere="); output(result); break; } default: printf("wrong Input\n"); } return 0; } int input() { int number; scanf("%d", &number;); return (number); } void output(float number) { printf("%f", number); } |
chevron_right
filter_none
Output:
Press 1 to calculate area of circle Press 2 to calculate area of square Press 3 to calculate area of sphere Enter your choice: 1 Enter radius: 5 Area of circle=78.5
Related Articles:
- Interesting facts about switch statement in C
- Output of C programs | Set 30 (Switch Case)
- Using range in switch case in C/C++
Recommended Posts:
- C Program for Program to find area of a circle
- C Program for Program for array rotation
- Lex Program to remove comments from C program
- Java program to check palindrome (using library methods)
- Program to calculate the value of sin(x) and cos(x) using Expansion
- C++ Program to concatenate two strings using Operator Overloading
- Basic calculator program using Python
- C program to copy string without using strcpy() function
- Program to find third side of triangle using law of cosines
- Program to print alphabet "A" using stars
- C program to print employee details using Structure
- C Program to Print Number series without using any loop
- C/C++ Program to check whether it is possible to make a divisible by 3 number using all digits in an array
- C program for file Transfer using UDP
- Python program to count upper and lower case characters without using inbuilt functions
- PHP | Program to delete an element from array using unset() function
- Program to find LCM of 2 numbers without using GCD
- Program to find GCD or HCF of two numbers using Middle School Procedure
- Program to Find the Largest Number using Ternary Operator
- Program to find Length of Bridge using Speed and Length of Train
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

