【发布时间】:2016-08-31 09:45:13
【问题描述】:
我要建左半金字塔
##
###
####
#####
######
#######
########
#########
这是我的代码:
#include <stdio.h>
#include <cs50.h>
int main(void)
{
printf("Enter the height of the pyramid:");
unsigned int height = GetInt();
int counter;
while(height <1 || height >23){
printf("Incorect number,try again:");
height = GetInt();
}
for(counter = 2;counter <=height+1;++counter) {
printf("%.*s\n", counter, "##############################");
}
}
我建造了金字塔,但不是左角,而是右角金字塔。 怎样才能把它转到左边呢?
PS 我知道,在这种情况下使用 printf 并不是最好的主意,但有人告诉我用这个命令创建代码。
【问题讨论】:
-
printf("%*.*s\n", height+1, counter,... -
@BLUEPIXY 谢谢,它有效。但是,你能解释一下这个 coude 是做什么的吗?我的意思是每个输入(尤其是第一个)。
-
@BLUEPIXY 现在我明白了。谢谢
-
@BLUEPIXY 考虑回答让 OP 接受。