spiderling66
Programmer
i am looking for the average of these double numbers, but i always got 5.0000, it's the accuracy lost, could anyone tell me what the problem is?
cheers
average (double a[], int n)
{
int i;
double av = 0.0;
for( i = 0; i < n; i++)
{
av += *a++;
}
return av;
}
main()
{
double a[] = {2.0, 3.5, 10.3};
double av = (average(a, 3))/3;
printf ("%lf\n", av);
}
cheers
average (double a[], int n)
{
int i;
double av = 0.0;
for( i = 0; i < n; i++)
{
av += *a++;
}
return av;
}
main()
{
double a[] = {2.0, 3.5, 10.3};
double av = (average(a, 3))/3;
printf ("%lf\n", av);
}