搜索
您的当前位置:首页正文

c++打印菱形

来源:榕意旅游网
#include <bits/stdc++.h>
using namespace std;

int main()
{
	cout << "Enter the length: " << endl;
	int n;
	cin >> n;

	for (int i = 1; i <= 2 * n - 1; i++)
	{
		for (int j = 1; j <= 2 * n - 1; j++)
			cout << ((j >= 1 + abs(i - n) && j <= 2 * n - 1 - abs(i - n)) ? "*" : " ");
		cout << endl;
	}
}
这是本蒟蒻能想到的行数最少的办法了。。。。。

因篇幅问题不能全部显示,请点此查看更多更全内容

Top