How many times will the body of the following loop be execut

问题描述:

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各一次?
1个回答 分类:英语 2014-11-27

问题解答:

我来补答
ecause 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.
:-)
 
 
展开全文阅读
剩余:2000