CS50 PSET 1 MARIO更多

发布于 2025-02-12 01:39:21 字数 837 浏览 1 评论 0原文

我在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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

不可一世的女人 2025-02-19 01:39:21

如果我正确阅读了您的问题,您想在终端上产生金字塔(或等质三角形),如以下示例(fyi,我只有一个空间)。

Height: 8

       # #
      ## ##
     ### ###
    #### ####
   ##### #####
  ###### ######
 ####### #######
######## ########

如果是这样,我相信您会使它复杂一些。实际上,您只想重复以对称方式创建的模式。为此,您只需要重复与产生图案的左半部分相同的打印循环。如果您需要更多提示,请告诉我。

顺便说一句,我相信您可以删除“ while”语句。

while(height < 1 || height > 8);

正如目前存在的那样,如果输入一个小于一个或大于八个的值,而循环只会成为无尽的循环。

希望有帮助。

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).

Height: 8

       # #
      ## ##
     ### ###
    #### ####
   ##### #####
  ###### ######
 ####### #######
######## ########

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.

while(height < 1 || height > 8);

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文