Here is a program in ANSI Standard C:
double sum, a[20];
int i;
/*
* Some code to initialize array a with legitimate
* floating point values whose sum is less than "maximum double".
*/
sum = 0.0;
for (i = 0; i < 20; i++)
sum += a[i];
printf("%e\n", sum);
sum = 0.0;
i = 20;
while (i--)
sum += a[i];
printf("%e\n", sum);
Question:
Will the 2 "printed" values:
1) always be the same? if so, explain why.
2) always be different? if so, explain why.
3) sometimes be the same and sometimes different? if so, give an
example.
double sum, a[20];
int i;
/*
* Some code to initialize array a with legitimate
* floating point values whose sum is less than "maximum double".
*/
sum = 0.0;
for (i = 0; i < 20; i++)
sum += a[i];
printf("%e\n", sum);
sum = 0.0;
i = 20;
while (i--)
sum += a[i];
printf("%e\n", sum);
Question:
Will the 2 "printed" values:
1) always be the same? if so, explain why.
2) always be different? if so, explain why.
3) sometimes be the same and sometimes different? if so, give an
example.