Suppose that on an amazing computer (call it Superman), variables with type floa
ID: 3560157 • Letter: S
Question
Suppose that on an amazing computer (call it Superman), variables with type float can store 3 decimal digits. Also suppose that Superman's floating point registers can store 4 decimal digits, and that after any floating point operation, the result is rounded to 3 decimal digits before being stored. Identify what the output would be of the following program if it were to be run on Superman:
float a[] = {4.0, 3.0, 3.0, 1000.0}
int i;
float sum = 0.0;
for (i = 0; i < 4; i++) {
sum += a[i];
}
printf("sum = %4.1f", sum);
Explanation / Answer
Here each of the element of the array contains only a single decimal digit,
Thus sum = 0.0 + 4.0 + 3.0 + 3.0 + 1000.0 = 1010.0
(This result doesnt need to be rounded bcoz it contains only a single decimal digit)
and printf("sum = %4.1f", sum); will print
sum = 1010.0
Plz rate
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.