解题思路:很简单自己看能懂
注意事项:
参考代码:
#include<iostream>
using namespace std;
char arr[50][50];
void Display(int size,int begin)
{
int i, j, k;
i = begin;
j = begin;
if (size < 0)
{
return;
}
for (k = 1; k < size; k++)
{
arr[i][j++] = '*';
}
for (k = 1; k < size; k++)
{
arr[i++][j] = '*';
}
for (k = 1; k < size; k++)
{
arr[i][j--] = '*';
}
for (k = 1; k < size; k++)
{
arr[i--][j] = '*';
}
Display(size - 4, begin + 2);
}
int main()
{
int n;
cin >> n;
Display(n, 0);
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
{
if (arr[i][j] == '*')
{
cout << arr[i][j];
}
else
{
cout << ' ';
}
}
cout << endl;
}
}
0.0分
1 人评分