a) What is the exact output of the code below if we execute the function call q2(20)?
void q2(int n)
{
for (int i = 1; i < n; i *= 2)
cout << i;
}
b) The function in part (a) uses a for loop. Rewrite the function using a while loop without changing how the code works.
c) Rewrite the function from part (a) using a do-while loop. (Hint: make sure the code produces the same output for all cases).

博客围绕一段代码展开,首先询问执行函数调用q2(20)的精确输出,该函数使用for循环。接着要求将此函数用while循环重写且不改变代码功能,最后还需用do - while循环重写该函数,确保所有情况输出相同。
3020

被折叠的 条评论
为什么被折叠?



