codeup之等腰梯形
Description
请输入高度h,输入一个高为h,上底边长为h 的等腰梯形(例如h=4,图形如下)。
****
******
********
**********
Input
输入第一行表示样例数m,接下来m行每行一个整数h,h不超过10。
Output
对应于m个case输出要求的等腰梯形。
Sample Input Copy
1
4
Sample Output Copy
****
******
********
**********
solution
#include <stdio.h>
int main(){
int m, n;
scanf("%d", &m);
while(m--){
scanf("%d", &n);
int col = 3*n - 2;
for(int i = 0; i < n; i++){
for(int j = 0; j < col; j++){
if(j>= n - 1 - i && j <= 2*n - 2 + i)
printf("*");
else
printf(" ");
}
printf("\n");
}
}
return 0;
}