fork download
  1. #include <iostream>
  2. #include <cmath>
  3. using namespace std;
  4.  
  5. int main() {
  6. int x, y;
  7. double n1, n2;
  8. double sum =0.0;
  9. double product= 1.0;
  10. double sumResiprocal =0;
  11. double arithm_M = 0;
  12. double geom_M = 0;
  13. double harmo_M = 0;
  14.  
  15. cout<<"Enter your first number :";
  16. cin>> n1;
  17.  
  18. cout<<"Enter your second number :";
  19. cin>>n2;
  20.  
  21. sum= n1+n2;
  22. product = n1*n2;
  23. sumResiprocal = 1.0/n1 + 1.0/n2;
  24.  
  25. arithm_M = sum/2.0;
  26. geom_M = pow(product, 1.0/2.0);
  27. harmo_M = 2/sumResiprocal;
  28.  
  29. cout<< "arithmetic mean is :" <<arithm_M<<endl;
  30. cout<< "geometric mean is" <<geom_M<<endl;
  31. cout<< "harmonic mean is" <<harmo_M<<endl;
  32.  
  33. return 0;
  34. }
Success #stdin #stdout 0s 4204KB
stdin
5 5
stdout
Enter your first number :Enter your second number :arithmetic mean is :5
geometric mean is5
harmonic mean is5