Write a C Program to Find Sum, Average and Standard Deviation for a Given Set of Values
Source Code:
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
float x[50];
int i,n;
float sum=0,avg,variance,stddev,d,varsum=0;
printf("\n Enter number of values\n");
scanf("%d",&n);
printf("\n Enter the values\n");
for(i=0;i<n;i++)
{
scanf("%f",&x[i]);
sum=sum+x[i];
}
avg=sum/(float)n;
for(i=0;i<n;i++)
{
d=x[i]-avg;
varsum=varsum+pow(d,2);
}
variance=varsum/(float)n;
stddev=sqrt(variance);
printf("\n Sum =%.2f",sum);
printf("\n Average =%.2f",avg);
printf("\n Standard Deviation =%.2f",stddev);
getch();
}
Output: