Computer Science, asked by anushka422497, 8 months ago

write a menu driven program using switch case to find the arithmetic mean, geometric mean and harmonic mean​

Attachments:

Answers

Answered by mad210203
4

Program is given below.

Explanation:

#include <stdio.h>

#include <math.h>

int main()

{

int a,b,choice;

float arithmetic_mean,geometric_mean,harmonic_mean;

printf("Enter the value of a and b: ");

scanf("%d %d",&a,&b);

printf("Enter your choice: ");

scanf("%d",&choice);

switch(choice){

   case 1:

          arithmetic_mean = ((float)(a+b)/2);

          printf("Arithmetic mean of %d and %d is: %f",a,b,arithmetic_mean);

          break;

   case 2:

          geometric_mean = (float)(sqrt(a * b));

          printf("Geometric mean of %d and %d is: %f",a,b,geometric_mean);

          break;

   case 3:

          harmonic_mean = ((2*a*b)/(float)(a+b));

          printf("Harmonic mean of %d and %d is: %f",a,b,harmonic_mean);

          break;

   default:

          printf("Something error occured!!\nEnter choice between 1 and

          3 only!");

          break;

   }

return 0;

}

Refer the attached image for the output.

Attachments:
Similar questions