write a menu driven program using switch case to find the arithmetic mean, geometric mean and harmonic mean
![](https://hi-static.z-dn.net/files/d55/3335ca7dd14cd5a2ca94d2d1be84e3f1.jpg)
Answers
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.
![](https://hi-static.z-dn.net/files/daf/425a7c070cdfef3916c8aeedc3b68195.jpg)
![](https://hi-static.z-dn.net/files/d87/1d2884e72acda7c4b93af93176df1e81.jpg)
![](https://hi-static.z-dn.net/files/dac/13ea312f61c15c6878ed6d659adfb828.jpg)