gpt4 book ai didi

创建一个 "Mario Style Pyramid"

转载 作者:太空狗 更新时间:2023-10-29 15:25:55 25 4
gpt4 key购买 nike

<分区>

我正在学习哈佛 CS50 在线类(class),其中一个问题是使用空格和哈希创建“马里奥风格金字塔”。我已经解决了空间问题,但哈希给我带来了麻烦。这是代码:

#include <stdio.h>
#include <cs50.h>

int main(void)
{
//get height between 1 and 23
int height;
do
{
printf("Please enter a height: ");
height = GetInt();
}
while (height < 1 || height > 23);

//build pyramid
for (int i = 0; i < height ; i++)
{
//add spaces
for (int space = height - 1 - i; space >= 0; space--)
printf(" ");

//add hashtags
for (int hash = 2 + i; hash <= height; hash++)
printf("#");

printf("\n");
}
}

当我在高度为 5 的终端中运行它时,我得到了这个:

     ####
###
##
#
<-- space here also

当我想要这个时:

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

如有任何反馈,我们将不胜感激

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com