How could I calculate several means using one set of user inputs?
I am trying to calculate an arithmetic, geometric, and harmonic mean as
well as a standard deviation, after prompting a user to input 5 integers.
I have the arithmetic mean working well. Its the others after it that are
troublesome.. I am almost positive it is because of my structuring, but I
just am not sure what to change after researching online and in my
textbook... and any help is appreciated with this!
Here is the code:
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
float a_mean;
float g_mean;
float h_mean;
float st_dev;
sum1 = 0; sum2 = 0; sum3 = 0;
float data[100];
n = 5;
int i;
int main()
{
printf("Please Enter Five Integers:\n"); /* Prompts user input */
for ( i = 0; i < n; ++i)
{
scanf("%f", &data[i]);
sum1 = sum1 + data[i];
}
a_mean = sum1 / n;
{
sum2 = sum2 * data[i];
}
g_mean = pow(sum2, 1 / n);
{
sum3 = sum3 + ( 1 / data[i] );
}
h_mean = n / sum3;
printf("Arithmetic mean: %0.2f\n", a_mean);
printf("Geometric mean: %0.2f\n", g_mean);
printf("Harmonic mean: %0.2f\n", h_mean);
return 0;
}
I know its probably something basic with my for-structuring, but I simply
don't know a lot about this stuff yet, so thanks in advance
No comments:
Post a Comment