输出梯形(清华大学复试上机题)
题目描述:输入一个高度h,输出一个高度为h,上底边长为h的梯形。
样例输入:4
样例输出:
#include<iostream> #include<cstdio> using namespace std; int main() { int h; cin >> h; //在对应位置填充‘*’ for (int i = 0; i <= h - 1; i++) { for (int j = 0; j < 2 * (h - 1 - i); j++) { cout << ' '; } for (int j = 2 * (h - 1 - i); j <= 3 * h - 3; j++) { cout << '*'; } cout << endl; } return 0; }