Vision and dreams are the blueprints of soul and achievements.
-Mohammed Ahmed F

Program to print Mean, Variance and Standard Deviation

#include <stdio.h>

#include <conio.h>
#include <math.h>
#define MAXSIZE 10

void main()
{
float x[MAXSIZE];
int   i, n;
float avrg, var, SD, sum=0, sum1=0;

clrscr();

printf("Enter the value of N\n");
scanf("%d", &n);

printf("Enter %d real numbers\n",n);
for(i=0; i<n; i++)
{
  scanf("%f", &x[i]);
}

/* Compute the sum of all elements */

for(i=0; i<n; i++)
{
  sum = sum + x[i];
}
avrg = sum /(float ) n;

/* Compute  variance  and standard deviation  */

for(i=0; i<n; i++)
{
  sum1 = sum1 + pow((x[i] - avrg),2);
}
var = sum1 / (float ) n;
SD = sqrt(var);

printf("Average of all elements  = %.2f\n", avrg);
printf("Variance of all elements = %.2f\n", var);
printf("Standard deviation       = %.2f\n", SD);
}  /*End of main()*/

Share this

Related Posts

Dear User,

Thank you for your comment. Hope you like this blog. Kindly share us on Social Media so others can be updated.

-Chief Administrative Officer.

Note: only a member of this blog may post a comment.