Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <math.h>
- double arithMean(double values[], int length)
- {
- double sum=0;
- for (int i = 0; i<length; i++)
- sum+=values[i];
- return sum/length;
- }
- double geomMean(double values[], int length)
- {
- double product=1;;
- for (int i = 0; i<length; i++)
- product*=values[i];
- product = pow(product, 1.0/length);
- return product;
- }
- double harmMean(double values[], int length)
- {
- double sum=0;
- for (int i = 0; i<length; i++)
- sum+=1.0/values[i];
- return length/sum;
- }
- int main()
- {
- double data[]= {23,37,14,8,64,52,32,18};
- int size=8;
- printf("Arithmetic mean = %f\n", arithMean(data, size));
- printf("Geometric mean = %f\n", geomMean(data, size));
- printf("Harmonic mean = %f\n", harmMean(data, size));
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment