如图所示然后输入9的话,会有一个倒三角形在上半部分显示。我只能用for loop尝试画出一个正方形,代码如下
int x;
cout << "Input: ";
cin >> x;
for (int r = 1; r <= x; r++)
{
for (int c = 1; c <= x; c++)
{
if (r == 1 || c == 1 || r == x || c == x)
cout << "*";
else
cout << " ";