Computer Science, asked by dharaankit308, 17 days ago

Write a Menu driven program (using switch ...case) to find out the area of a circle ( area = P!
radius), a square ( area= side), a triangle ( are = 1/2 x height x base) as per user's choice
Accept the values of radius of a circle, side of a square and base and height of a triangle from user​

Answers

Answered by sanjumanoj9567
0

// 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);

}

Similar questions