Something is wrong in what you originally stated: This works just fine:

Code:

#include <stdio.h>
#include <stdlib.h>
#define SIZE 10001
double frand(double maxval)
{
#if 0
// Set above to 1 for testing the max value possible.
return maxval;
#else
return ((double)rand() / RAND_MAX) * maxval;
#endif
}
int main()
{
double a[SIZE];
double sum = 0;
int i;
for(i = 0; i < SIZE; i++)
{
a[i] = frand(10.0);
}
for(i = 0; i < SIZE; i++)
{
sum += a[i];
}
printf("sum = %f, avg = %f\n", sum, sum / SIZE);
return 0;
}

The sum, when using random values is about 50000, and the average 5.0 something - which is exactly what one would expect.

If you get other values, I'd suggest you add a bit of code like this:

Code:

double max = -100000.0, min = 1000000.0;
for(i = 0; i < SIZE; i++)
{
if (max < a[i]) max = a[i];
if (min > a[i]) min = a[i];
}

print max and min after the loop, to see if it's the expected range. I suspect you are having "garbage" in your array.

--

Mats