QUESTION 2 The code below is supposed to add the numbers from 1 up to and including 10. It does not calculate the correct sum. The problem is caused by a(n) ________ error. int sum = 0; for (int count = 1; count < 10; count++) sum += count; a. syntax b. compilation c. requirement d. off-by-one e. testing

Respuesta :

ijeggs

Answer:

d) off-by-one error

Explanation:

This type of error is a logical error that makes our programs give unexpected results after compilation. It usually involves an iterative loop going one time more or less than expected.

For the problem in this question the statement for (int count = 1; count < 10; count++), will iterate from 1 to 9 and not include 10. To correct this since the program is supposed to add the sum of numbers from 1 up to and including 10, we must add a (<=). The statement becomes for (int count = 1; count < =10; count++)

Q&A Education