Somethings I should say: this is the first time I make a question in here. Usually, when I'm with a doubt about something, I found it answered somewhere (including I found a lot of answers in this website). But this time, I'm not finding an answer, so if there was, I didn't find and I'm sorry for making a question that has already been made (I know you guys don't like it, but I promise that I've searched).
I came out with this doubt by helping to sove another person's doubt. Well, I'm not sure how to say this in English, but I believe it is: "standard deviation" (Standard Deviation on Wikipedia). That's what the program is about.
A person came with a question how to do this, it wasn't working... I didn't know the formula to calculate the standard deviation, but he gave to me. But the one he gave was wrong. I'll show the code of how the program is: PasteBin of My Standard Deviation Code
It seems to be working now with this way I did, but I'm not sure. I gave this solution to the person who asked my help. Is the program right?
But my real question is not if the program is right. There is this part on the code:
sum += pow(v[i] - m,2);
When he gave me the wrong formula it was:
sum += v[i] - m;
Can you guys compile that wrong code? Depending on the numbers that you put, the output is -1.#J. Why's that? What does this mean?
#include <stdio.h>
#include <math.h>
int main (void)
{
int n = 10, i;
double d, m = 0.0f, sum = 0.0f, v[10];
for (i = 0; i < n; i++)
{
printf ("Inform a real number: ");
scanf ("%lf",&v[i]);
m += v[i];
}
m /= n;
for (i = 0; i < n; i++)
sum += pow(v[i] - m,2);
d = sqrt (sum/(n-1));
printf ("The standard deviation of vector v is = %.2lf\n\n",d);
return 0;
}