Lab1_q2

Run Settings
LanguageC++
Language Version
Run Command
#include <iostream> #include <cmath> using namespace std; double AM(double a, double b) { return (a+b)/2; }// AM = (a + b + c + d + e)/5 double GM(double a, double b) { if(a*b < 0){ return -1; }else{ return pow(a*b,0.5); } }// GM = (abcde)^(1/5) double HM(double a, double b) { if(a == 0 || b == 0){ return -1; }else{ return 1/((1/a + 1/b)/2); } }// GM = 1/ ((1/a + 1/b +1/c + 1/d + 1/e)/5) int main() { cout << "The arithmetic mean of 3 and 5 is: " << AM(3,5) << endl; cout << "The geometric mean of 3 and 5 is: " << GM(3,5) << endl; cout << "The harmonic mean of 3 and 5 is: " << HM(3,5) << endl; return 0; }
Editor Settings
Theme
Key bindings
Full width
Lines