How many times will the body of the following loop be executed?int sum = 0; int n;for (n = 9; n > 0; n = n / 2)sum = sum + n;(a) once(b) twice(c) four times(d) three times 为什么答案是三次呢?不是四次么?n=9,4,2,1各一次?

来源:学生作业帮助网 编辑:作业帮 时间:2024/04/27 13:52:55
How many times will the body of the following loop be executed?int sum = 0; int n;for (n = 9; n > 0; n = n / 2)sum = sum + n;(a) once(b) twice(c) four times(d) three times 为什么答案是三次呢?不是四次么?n=9,4,2,1各一次?

How many times will the body of the following loop be executed?int sum = 0; int n;for (n = 9; n > 0; n = n / 2)sum = sum + n;(a) once(b) twice(c) four times(d) three times 为什么答案是三次呢?不是四次么?n=9,4,2,1各一次?
How many times will the body of the following loop be executed?
int sum = 0;
int n;
for (n = 9; n > 0; n = n / 2)
sum = sum + n;
(a) once
(b) twice
(c) four times
(d) three times
为什么答案是三次呢?不是四次么?n=9,4,2,1各一次?

How many times will the body of the following loop be executed?int sum = 0; int n;for (n = 9; n > 0; n = n / 2)sum = sum + n;(a) once(b) twice(c) four times(d) three times 为什么答案是三次呢?不是四次么?n=9,4,2,1各一次?
because the first time n=4; second time n=2; third time n=1.
no more.
the question is how many time the body is executed,however n=9 is defined,not a result from execution.
:-)