【发布时间】:2022-11-21 04:19:30
【问题描述】:
我试图理解并弄清楚如何制作一个从左到右的金字塔。
我有电脑问身高,只有1-8
我试图根据高度使金字塔看起来像这样
我做了一个平方。 这是代码
#include <cs50.h>
#include <stdio.h>
int main(void)
{
int getHeight;
do
{
//asks height
getHeight = get_int("Height: ");
}
//If the height is greater then 8 then ask for the Height again
while(getHeight > 8);
//
for(int row = 0; row < getHeight; row++)
{
for(int colums = 0; colums < getHeight; colums++)
{
printf("#");
}
printf("\n");
}
}**
【问题讨论】:
-
花点时间考虑一下。也许用笔和纸把它画出来,想出一个算法。例如,对于第一行,您应该打印多少列?