Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a C program that accepts 5 integers from a user and then calculates their

ID: 3883707 • Letter: W

Question

Write a C program that accepts 5 integers from a user and then calculates their arithmetic mean, geometric mean, harmonic mean, and standard deviation. The program should then print and label the original 5 numbers and the four statistics. You will need to include the math library (#include math) to use pow() and squareroot () Equations: Arithmetic Mean: X bar = sigma_i = 1^n X_i Geometric Mean: (Product_i = 1^n a_1)^1/n = n squareroot a_1 * a_2 * a_n Harmonic Mean: Standard Deviation: S = squareroot sigma_i-1^n (X_i - X)^2/n Here is a sample of what you program should do. Please Enter Five Integers: 85 43 95 100 78 Data: 85 43 95 100 78 Results: Arithmetie Mean = 80.2 Geometric Mean = 77.0089 Harmonic Mean = 73.1343 Standard Deviation = 20.1137

Explanation / Answer

code:

#include<stdio.h>
#include<math.h>
int main()
{
int n,i;
double am=0;
double ans=1.0,l=0.0,m=0.0;
scanf("%d",&n);
int a[n];
for( i=0;i<n;i++)
{

scanf("%d",&a[i]);
am+=a[i];
ans*=a[i];
l+=1.0/a[i];
}
double z=am/n;

for( i=0;i<n;i++)
{
double x=z-a[i];

if(x<0)
{
x=-x;
}

m=m+pow(x,2);

//printf("%f ",m);
}
printf("data: ");
for(i=0;i<n;i++)
{

printf("%d ",a[i]);
}
printf("results ");
printf("arthemetic mean =g ",am/n);
printf(" geaometric mean =%g ",pow(ans,0.2));
printf("harmonic mean = %g ",n/l);

printf("standard deviation = %g",sqrt(m/n));//sqrt(m/5.0));


return 0;
}

output:

data:
85
43
78
95
100
results

arthemetic mean =80.2
geaometric mean =77.0089
harmonic mean = 73.1343
standard deviation = 20.1137

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote