Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <math.h>
- float avg(double max, float sum);
- float geom(double numbers, float prod);
- float harm(double numbers, float denominator);
- int main (void)
- {
- int a;
- double tnumbers;
- float input, sum, product, denominator;
- printf("How many numbers? ");
- scanf("%lf", &tnumbers);
- for(a=0; a<tnumbers; a++)
- {
- printf("Enter a number: ");
- scanf("%f", &input);
- sum += input;
- product *= input;
- denominator += (1/input);
- }
- printf("Average = %f\n", avg(tnumbers, sum));
- printf("Geometric = %f\n", geom(tnumbers, product));
- printf("Harmonic = %f\n", harm(tnumbers, denominator));
- return 0;
- }
- float avg(double max, float sum)
- {
- float average=0;
- return average = sum / max;
- }
- float geom(double numbers, float product)
- {
- float geoMean = (product)pow(1 / numbers);
- return geoMean;
- }
- float harm(double numbers, float denominator){
- float harmonicMean = numbers / denominator;
- return harmonicMean;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement