pls soon reply
C program to find the standard deviation. i need program also explain the process?
#include%26lt;stdio.h%26gt;
#include%26lt;conio.h%26gt;
#include%26lt;math.h%26gt;
void main()
{
int n,i,j; /*initialising the variables */
double max[100],sum=0,variance,mean=0;
printf('enter the size of array \n");
scanf("%d",%26amp;n); /*reading the no of elements we needed */
printf("enter the elements of array:\n");
for(i=0;i%26lt;n;i++) /*reading the elements to array max[ ]*/
scanf("%lf",%26amp;max[i]);
i=0; /* initializing the variable to zero.This variable can be used as outer loop variable*/
printf ("\n");
/*loop written to calculate the summation which we can see in the formula (refer to formula of mean)*/
for(j=0;j%26lt;n;j++)
{
sum+=max[i];
i++;
}
mean=sum/i; /* calculating the mean value */
printf("sum of the elements:");
printf("%lf",sum);
printf("mean of the elements:");
printf("%lf",mean);
i=0; /*resetting the variable to zero %26amp; here also it works as outer loop variable in calculating the variance*/
sum=0; /* reset the sum to zero*/
for(j=0;j%26lt;n;j++) /* calculating summation in variance formula (refer to variance formula )*/
{
max[i]=pow((max[i]-mean),2);
sum+=max[i];
i++;
}
variance=sum/(i-1); /* calculating variance*/
printf("standard deviation:"); /* printing the standard deviation as it is the square root of
printf("%lf",sqrt(variance)); variance*/
}
peony
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment