Tuesday, August 10, 2010

MEAN AND STANDARD DEVIATION

0 comments
#include<stdio.h> 
#include<conio.h>
#include<math.h> 
void main()
{
int n,a[25],i;
float sum=0,sos=0,q,m,sd;
clrscr();
printf("Enter the total number of elements:");
scanf("%d",&n);
printf("Enter the elements");
for(i=1;i<=n;i++)
{
scanf("%d",&a[i]);
sum=sum+a[i];
sos=sos+a[i]*a[i];
}
m=sum/n;
q=sos/n;
sd=sqrt(q-m*m);
printf("The mean of given numbers is=%f",m);
printf("Standard deviation is =%f",sd);
getch();
}




Algorithm:

1.Start.
2.Read n.
3.assign i=1,sum=0,sos=0
4.If i<=n goto step5 else goto step9.
5.Read a[i]
6.Compute sum=sum+a[i]
7.Compute sos=sos+a[i]*a[i]
8.Assign i=i+1 goto step4.
9.compute m=sum/n
10.Compute q=sos/n
11.Compute sd=sqrt(q-m*n)
12.Print m,sd
13.Stop

Leave a Reply