【发布时间】:2014-05-23 12:56:53
【问题描述】:
我想知道,为什么在输出中指定的地方打印了空行。 这对我来说没有意义,因为这意味着即使测试条件为假,循环也会继续。 (这是《C Primer Plus》第6章第9题)
#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");中的***之前打印了一个空行??