Write a C Program to input numbers and to find mean variance and standard deviation.

#include<stdio.h>
#include<conio.h>
#include<math.h>
main()
{
   int i,n;
   float std_dev,sum=0,sumsqr=0,mean,value,variance=0.0,a[100];
   clrscr();
   printf("\nEnter number of data points");
   scanf("%d",&n);
   printf("\nEnter data points");
   for(i=0;i<n;i++)
   {
      printf("\nPoint %d:",i+1);
      scanf("%f",&a[i]);
      sum=sum+a[i];
   }
   mean=sum/n;
   sumsqr=0;
   for(i=0;i<n;i++)
   {
     value=a[i]-mean;
     sumsqr=sumsqr+value*value;
    }
     variance=sumsqr/n;
     std_dev=sqrt(variance);
     printf("\nMean=%f",mean);
     printf("\nVariance=%f",variance);
     printf("\nstd_dev=%f",std_dev);
     getch();
     return;
}

No comments:

Post a Comment