728x90 AdSpace

Latest News

Thursday, 3 July 2014

Write a C program to input real numbers and find the mean, variance and standard deviation

 Write a C program to input real numbers and find the mean, variance and standard deviation  

#include <stdio.h>
#include <conio.h>
#include <math.h>
#define MAXSIZE 10
 
int main()
{
   float x[MAXSIZE];
   int  i, n;
   float avrg, var, SD, sum=0, sum1=0;

   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);
   return 0;
}


Write a C program to input real numbers and find the mean, variance and standard deviation
  • Blogger Comments
  • Facebook Comments

0 comments:

Post a Comment

Top