输出梯形

#include<stdio.h>

// ****
// ******
// ********
//**********
//梯形高度是h,故图形的行数是h
//首行有h个*,下一行总是比上一行多2个*,故第i行有 h+2*i
//最后一行中*的数量决定了图像的列数
//每行都右边对齐,左边空余的位置输出空格,空格数是列数与该行中*的数量之差。
int main()
{
int row,h,col;

while(scanf("%d",&h)!=EOF)
{
row = h;
col = h+2*(h-1);
for(int i=0;i<row;i++){
for(int j=0;j<col;j++)
{
if(j<col-(h+2*i))
{
printf(" ");
}
else
{
printf("*");
}
}
printf("\n");
}

}

}

posted @ 2022-03-01 14:02  城北徐公135  阅读(84)  评论(0)    收藏  举报