Quick actions

cmd+k|ctrl+k

Navigation

Languages

Lab1_q2

Snippet info

Language

Cpp

Visibility

public

Author

chriscui14

Created

2020-05-28T20:43:52Z

Updated

2020-05-28T21:15:10Z

#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;
}
INFO