我的代码:
#define RUNS 4
int main (int argc, char *argv[])
{
srand(time(NULL));
int i;
int _length;
float _totalTimeToReachLength;
float _arrayOfTimes[RUNS - 1];
float _sumDev = 0.0;
for (i = 0; i < RUNS; i++)
{
float localHopNumber = GenerateHops(_length); //pass length into hops method.
_arrayOfTimes[i] = localHopNumber; //add hop number generated to array.
_sumDev = (_sumDev + (_arrayOfTimes[i]-(_totalTimeToReachLength / RUNS)) * (_arrayOfTimes[i]-(_totalTimeToReachLength / RUNS))); //work out sd.
_totalTimeToReachLength = _totalTimeToReachLength + _arrayOfTimes[i];
printf("Current increment for average: %f\n", _totalTimeToReachLength);
printf("Item added to array: %f\n", _arrayOfTimes[i]);
}
printf("The standard deviation of times is: %f\n", sqrt(_sumDev/RUNS));
printf("The standard average of times is: %f\n", _totalTimeToReachLength / RUNS);
return 0;
}
为什么它在最后一个循环中搞砸了?