Solved
Finding the Standard deviation from a structure of numbers
Posted on 2003-11-25
Im trying to find the standard deviation from a structure of numbers.
the array is in the format:
s[x].sid= 301111;
s[x].mark= 50;
s[x].grade= 'A';
were x is incremented for every user.
heres the code for the standard deviation, its in the form of a function initalised using:
float stdDev(struct student s[], int n);
and called using:
stdDev(staff,ARR_SIZE);
heres the function... it just crashes! theres 5 entrys, which should be passed to the function in n
float stdDev(struct student s[], int n)
{
int x;
float mean, sigma;
mean = s[x].sid / n;
for (x=0; x<5; x++) n += (mean - s[x].mark)*(mean-s[x].mark);
sigma = sqrt(n/5);
printf("Std Deviation is %f",sigma);
return sigma;