C++大學教程(第九版) 第5章練習題 5.24 修改星號組成的菱形圖案

#include <iostream>
using namespace std;

int main() {
	int h;
	cin >> h;
	for(int i = 1; i <= h / 2 + 1; i++) {
		for(int j = h / 2 + 1 - i; j > 0; j--)
			cout << ' ';
		for(int j = i * 2 - 1; j > 0; j--)
			cout << '*';
		cout << endl;
	}
	for(int i = 1; i <= h / 2; i++) {
		for(int j = i; j > 0; j--)
			cout << ' ';
		for(int j = h - 2 * i; j > 0; j--)
			cout << '*';
		cout << endl;
	}
	return 0;
} 
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章