Calculate standard deviation with an array in C

Hey guys, so i have some code that calculates the minimum, maximum, and average of numbers entered using an array in C. However, i need to get it to calculate the standard deviation of these numbers, but i've no idea how the formula works, or how to implement it! Help would be much appreciated please (:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <stdio.h>
#include <math.h>

void main()
{
	int count, max, min;
	float total, average, standarddev=0;
	int myarray[5];

	total = 0;

	for (count = 0; count < 5; count++)
	{
		printf("Please enter a number: ");
		scanf("%d",&myarray[count]);
		total = total + myarray[count];
	}

	average = total / 5;
	printf("\n\nThe average of the numbers entered is : %.2f\n\n",average);

	standarddev = sqrt([average]/5.0);

	min = myarray[0];
	max = myarray[1];

	for (count = 0; count <5; count ++)
	{
		if(myarray[count]>=max)
		{
			max=myarray[count];
		}
		else if(myarray[count]<=min)
		{
			min=myarray[count];
		}
	}
	printf("\nThe maximum number is: %d\n\n",max);
	printf("\nThe minimum number is: %d\n\n",min);

	

	printf("\nThe standard deviation of the numbers entered is : %f\n\n",standarddev,average);

}
Well, I really shouldn't answer at all, since you have the knowledge of the internet at your fingertips and could therefore easily google it yourself, but the formula for stddev is sqrt(sigma{1,n}[(yi-mean)^2]/n)
so i need to calculate the mean first and then get the standard dev that way?

i am being generally lazy, its not the formula thats a problem, i did google that to begin with, not completely useless -.-

however, i didn't know how to program it in C.
Last edited on
Compute the mean.

Loop through the data, and add together each ( element - mean )^2.

Then divide that sum by number of elements.

Lastly take square root of that.
Topic archived. No new replies allowed.