CS50 PSET 1 MARIO更多
我在CS50 PSET 1中更舒适地解决Mario,我确实喜欢它,这是我的代码:
#include <cs50.h>
#include <stdio.h>
int main(void)
{
int height, i2, i;
do
{
height = get_int("Height: ");
}
while(height < 1 || height > 8);
for(i = 0; i < height; i++)
{
printf("\n");
for(int o = 0; o < height - i - 1; o++)
{
printf(" ");
}
for(int j = 0; j <= i; j++)
{
printf("#");
}
printf(" ");
for(i2 = 0; i2 < height; i2++)
{
//printf("\n");
for(int j2 = 0; j2 <= i2; j2++)
{
printf("#");
}
}
}
printf("\n");
}
它很好地绘制了第一个金字塔,并放置了两个空间,但是它不是金字塔,而是绘制了一个矩形。我在互联网上搜索了答案,但是所有这些都只是在解决整个过程,这会破坏学习过程,所以您能给我一些暗示吗?非常感谢您提供的任何帮助。
I'm solving Mario More comfortable in CS50 Pset 1, I did like most of it, and this is my code:
#include <cs50.h>
#include <stdio.h>
int main(void)
{
int height, i2, i;
do
{
height = get_int("Height: ");
}
while(height < 1 || height > 8);
for(i = 0; i < height; i++)
{
printf("\n");
for(int o = 0; o < height - i - 1; o++)
{
printf(" ");
}
for(int j = 0; j <= i; j++)
{
printf("#");
}
printf(" ");
for(i2 = 0; i2 < height; i2++)
{
//printf("\n");
for(int j2 = 0; j2 <= i2; j2++)
{
printf("#");
}
}
}
printf("\n");
}
It draws the first pyramid well and puts two spaces, but instead of a pyramid, it draws something like a rectangle. I searched the internet for answers but all of them were just solving the whole thing and that spoils the learning process, so can you please give me some hints about this? I really appreciate any help you can provide.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果我正确阅读了您的问题,您想在终端上产生金字塔(或等质三角形),如以下示例(fyi,我只有一个空间)。
如果是这样,我相信您会使它复杂一些。实际上,您只想重复以对称方式创建的模式。为此,您只需要重复与产生图案的左半部分相同的打印循环。如果您需要更多提示,请告诉我。
顺便说一句,我相信您可以删除“ while”语句。
正如目前存在的那样,如果输入一个小于一个或大于八个的值,而循环只会成为无尽的循环。
希望有帮助。
If I am reading your question correctly, you want to produce a pyramid (or isosceles triangle) on the terminal like the following example (FYI, I have just one space).
If that is the case, I believe you complicated it a bit. In effect, you just want to repeat the pattern you have created in a symmetrical fashion. For that, you would only need to repeat the same print loop that you used to produce the left half of the pattern. If you need some more hints, let me know.
By the way, I believe that you can remove the "while" statement.
As it exists right now, if a value is entered that is less than one or greater than eight, that while loop will just become an endless loop.
Hope that helps.