输出梯形

问题 A: 输出梯形
时间限制: 1 Sec 内存限制: 32 MB
提交: 964 解决: 347
[提交][状态][讨论版][命题人:外部导入]
题目描述
输入一个高度h,输出一个高为h,上底边为h的梯形。

输入
一个整数h(1<=h<=1000)。

输出
h所对应的梯形。

样例输入
5
样例输出
*****
*******
*********



自己代码:
#include
int main() {
int h; char a[1000][3000];

while(scanf("%d", &h)!=EOF){
	for (int i = 0; i<h; i++)
		for (int j = 0; j<h + (h - 1) * 2; j++) {
			a[i][j] = ' ';
		}
	for (int i = 0; i<h; i++)
		for (int j = h + (h - 1) * 2 - 1; j >= h + (h - 1) * 2 - 1 - (h + 2 * i - 1); j--)
		{
			a[i][j] = '*';
		}

	for (int i = 0; i<h; i++)
		for (int j = 0; j<h + (h - 1) * 2; j++)
		{
			printf("%c", a[i][j]);
			if (j == h + (h - 1) * 2 - 1)
				printf("\n");
		}
}

system("pause");
return 0;

}
注意:
当我申请数组为a[1000][3000]时运行代码黑框闪一下没了,改成a[100][300]小一点的空间却正常运行,我在想是不是申请空间大大了,不足了。

猜你喜欢

转载自blog.csdn.net/qq_35966478/article/details/86561170