Advertisement
horselurrver

Harmonic Mean

Aug 2nd, 2016
283
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.41 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. float harmonic_mean(float x, float y);
  4. #define NUM1 7.90
  5. #define NUM2 12.123
  6. int main(void){
  7.     printf("The harmonic mean of %.2f and %.2f is %.2f\n", NUM1, NUM2, harmonic_mean(NUM1, NUM2));
  8.     return 0;
  9. }
  10.  
  11. float harmonic_mean(float x, float y){
  12.     float inverse1, inverse2, average;
  13.     inverse1=1/x;
  14.     inverse2=1/y;
  15.     average=(inverse1+inverse2)/2;
  16.     return 1/average;
  17. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement