I made a simple program but it's printing "twoi=..."
instead of "two"
. I tried re-arranging the for
-loop in the program:
我做了一个简单的程序,但它打印“twoi = ...”而不是“two”。我尝试在程序中重新安排for循环:
#include <stdio.h>
int main()
{
int i;
for (i = 1; i <= 10; ++i)
{
if (i == 2)
{
printf("two");
}
printf("i = %d\n", i);
}
return 0;
}
1 个解决方案
#1
1
Add a newline after "two"
:
在“two”之后添加换行符:
#include <stdio.h>
int main()
{
int i;
for (i = 1; i <= 10; ++i)
{
if (i == 2)
{
printf("two\n");
}
printf("i = %d\n", i);
}
return 0;
}
... or use puts()
which adds a newline by itself: puts("two");
...或者使用puts(),它自己添加换行符:puts(“two”);
#1
1
Add a newline after "two"
:
在“two”之后添加换行符:
#include <stdio.h>
int main()
{
int i;
for (i = 1; i <= 10; ++i)
{
if (i == 2)
{
printf("two\n");
}
printf("i = %d\n", i);
}
return 0;
}
... or use puts()
which adds a newline by itself: puts("two");
...或者使用puts(),它自己添加换行符:puts(“two”);