0
我想知道为什么在输出中指定的位置打印有空行。 它对我没有意义,因为这意味着即使测试条件为假,循环也会继续。 (这是在第6章 “C的Primer Plus” 的第9审查问题)C练习 - 循环 - 意外输出:空行
#include <stdio.h>
int main(void)
{
int n, m;
n = 30;
while (++n <= 33)
printf("%d|",n);
n = 30;
do
printf("%d|",n);
while (++n <= 33);
printf("\n***\n");
for (n = 1; n*n < 200; n += 4)
printf("%d\n", n); // Why will this print an empty line at the end?
printf("\n***\n");
for (n = 2, m = 6; n < m; n *= 2, m+= 2)
printf("%d %d\n", n, m); // and this
printf("\n***\n");
for (n = 5; n > 0; n--)
{
for (m = 0; m <= n; m++)
printf("=");
printf("\n");
}
return 0;
}
产生输出:
31|32|33|30|31|32|33|
***
1
5
9
13
(<= Why is there an empty line here?)
***
2 6
4 8
8 10
(<= and here?)
***
======
=====
====
===
==
你只是在'printf(“\ n *** \ n”)中打印了一个额外的'\ n';'(在开头宁)。 –
因为在printf(“\ n *** \ n”)中的'***'之前打印了一个空行;'? – Matt