This C Program calculates the mean, variance & standard deviation. The formula which is used in this program are mean = average of the numbers. variance = (summation( ( Xi – average of numbers) * ( Xi – average of numbers)) ) / Total no of elements. where i = 1 to N here N is the total no of elements. Standard deviation = Squareroot of the variance.

Here is source code of the C program to calculate the mean, variance & standard deviation. The C program is successfully compiled and run on a Linux system. The program output is also shown below.

`/*`

`* C program to input real numbers and find the mean, variance`

`* and standard deviation`

`*/`

`#include <stdio.h>`

`#include <math.h>`

`#define MAXSIZE 10`

void main()

`{`

float x[MAXSIZE];

int i, n;

float average, variance, std_deviation, 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];

`}`

average = sum / (float)n;

`/* Compute variance and standard deviation */`

for (i = 0; i < n; i++)

`{`

sum1 = sum1 + pow((x[i] - average), 2);

`}`

variance = sum1 / (float)n;

std_deviation = sqrt(variance);

printf("Average of all elements = %.2f\n", average);

printf("variance of all elements = %.2f\n", variance);

printf("Standard deviation = %.2f\n", std_deviation);

`}`

advertisements

$ cc pgm23.c -lm $ a.out Enter the value of N 5 Enter 5 real numbers 34 88 32 12 10 Average of all elements = 35.20 variance of all elements = 794.56 Standard deviation = 28.19

**Sanfoundry Global Education & Learning Series – 1000 C Programs.**

Here’s the list of Best Reference Books in C Programming, Data-Structures and Algorithms

If you wish to look at other example programs on Mathematical Functions, go to C Programming Examples on Mathematical Functions. If you wish to look at programming examples on all topics, go to C Programming Examples.