Advertisement
Guest User

Untitled

a guest
Oct 25th, 2014
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.00 KB | None | 0 0
  1.  
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <math.h>
  5.  
  6.  
  7. float avg(double max, float sum);
  8. float geom(double numbers, float prod);
  9. float harm(double numbers, float denominator);
  10.  
  11.  
  12. int main (void)
  13. {
  14.     int a;
  15.     double tnumbers;
  16.     float input, sum, product, denominator;
  17.     printf("How many numbers? ");
  18.     scanf("%lf", &tnumbers);
  19.  
  20.     for(a=0; a<tnumbers; a++)
  21.     {
  22.    
  23.         printf("Enter a number: ");
  24.         scanf("%f",  &input);      
  25.         sum += input;
  26.         product *= input;
  27.         denominator += (1/input);  
  28.     }
  29.    
  30.     printf("Average = %f\n", avg(tnumbers, sum));
  31.     printf("Geometric = %f\n", geom(tnumbers, product));
  32.     printf("Harmonic = %f\n", harm(tnumbers, denominator));
  33.     return 0;
  34. }
  35.  
  36.  
  37. float avg(double max, float sum)
  38. {
  39.     float average=0;
  40.     return average = sum / max;
  41. }
  42.  
  43. float geom(double numbers, float product)
  44. {
  45.     float geoMean = (product)pow(1 / numbers);
  46.     return geoMean;
  47. }
  48.  
  49. float harm(double numbers, float denominator){
  50.     float harmonicMean = numbers / denominator;
  51.     return harmonicMean;
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement