85. C Program to find Mean, Variance, Standard-deviation of a given number.
How does this program work?
- This Program is used to find mean, variance, standard deviation of a given number.
Here is the code
#include <stdio.h>
int main(void)
{
// Initialize the variables
int i,j,n;
float mean,sum=0.0,Ams=0.0,Msd,SD,a[n],Dms[n];
//Initialize number in n variable
printf("Enter number of terms\n");
scanf("%d",&n );
printf("Enter Numbers \n");
for(i=0;i< n;i++)
{
scanf("%f",&a[i] );
sum+=a[i];
}
//Compute mean
mean=(float)(sum/n);
printf("Mean for given numbers is %f\n",mean );
//Compute Variance and standard deviation
for(i=0;i < n;i++ )
{
Dms[i]=(a[i]-mean)*(a[i]-mean);
Ams+=Dms[i];
}
Msd=(float)(Ams/n);
SD=(float)(sqrt(Msd));
printf("Variance =%f\n",Msd );
printf("Sandard Deviation=%f\n",SD );
return 0;
}