Analyze the following fragment:
```
double sum = 0;
double d = 0;
while (d != 10.0) {
d += 0.1;
sum += sum + d;
}
```
a. The program does not compile because sum and d are declared double, but assigned with integer value 0.
b. The program never stops because d is always 0.1 inside the loop.
c. The program may not stop because of the phenomenon referred to as numerical inaccuracy for operating with floating-point numbers.
d. After the loop, sum is 0 + 0.1 + 0.2 + 0.3 + ... + 1.9
c. The program may not stop because of the phenomenon referred to as numerical inaccuracy for operating with floating-point numbers.
The correct answer is C. There is no guarantee that d will be exactly 10.0 because real numbers are represented using approximation in a computer system.
You might also like to view...
The most important general categories of data are: addresses, numbers, characters, and _________.
Fill in the blank(s) with the appropriate word(s).
The fork system call returns 0
A. when the new process finishes B. in the new process