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 (:
#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];
}
elseif(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)