Sunday, May 5, 2013

Write a C program to calculate mean and standard deviation of a population


/*Write a C program to calculate mean and standard deviation of a population*/
#include<stdio.h>
#include<conio.h>
main()
{
    float s=0,ss=0;
    int n,i,m;
    clrscr();
    printf("Enter the number of students:");
    scanf("%d",&n);
    i=0;
    while(i<n)
    {
      printf("Enter the student marks:\n");
      scanf("%d",&m);
      s=s+m;
      ss=ss+m*m;
      i++;
    }
    s=s/n;
    ss=sqrt((ss/n)-s*s);
    printf("Mean=%f \nStandard deviation=%f\n",s,ss);
    getch();
}
output:

Enter the number of students:2
Enter the student marks:
12
Enter the student marks:
21
Mean=16.500000
Standard deviation=-32664.000000

0 comments:

Post a Comment

Twitter Delicious Facebook Digg Stumbleupon Favorites More