CS50马里奥的问题少 - 我的代码是在一行中打印的。我找不到它怎么了
#include <cs50.h>
#include <stdio.h>
int main(void)
{
int n;
do
{
n = get_int("Height: ");
}
while ((n < 1) || (n > 8));
for
(int i = 0; i < n; i++)
{for (int j = 0; j < n; j++)
if(i+j < n-1)
printf(" ");
else
printf("#");
}
printf("\n");
}
#include <cs50.h>
#include <stdio.h>
int main(void)
{
int n;
do
{
n = get_int("Height: ");
}
while ((n < 1) || (n > 8));
for
(int i = 0; i < n; i++)
{for (int j = 0; j < n; j++)
if(i+j < n-1)
printf(" ");
else
printf("#");
}
printf("\n");
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
确保使用
{}
将每个循环和 if condice> condice> condiflational
包围。此
的 blocks ,因此准确打印一次。 (闭合支架printf(“ \ n”);
是 两个}
在最终printf
关闭i
循环的代码块)。Make sure you use
{}
to enclose codes blocks for everyfor
loop andif
conditional. Thisprintf("\n");
is outside bothfor
blocks and thus prints exactly once. (The closing brace}
before the finalprintf
closes the code block of thei
loop).您的代码格式不佳,这使您自己很难:
因此,您运行循环,然后打印一个新的新线。目前尚不清楚您是否需要:
Your code is formatted poorly which makes it hard for yourself:
So you run you loops then print a single newline. It's not clear if you want: