Description
由键盘输入正数n(n<30),要求输出如下2*n+1行的菱形图案。
输出格式
菱形右边不留多余空格
输入样例
2
输出样例
*
***
*****
***
*
#include <iostream>
using namespace std;
int getNum(int num)
{
if(num == 1)return 1;
return getNum(num-1)+2;
}
int main()
{
int xx, temp, yy;
cin >>xx;
xx++;
for(int i = 1; i <= xx; ++i)
{
temp = xx - i;
while(temp)
{
cout << " ";
temp--;
}
yy = getNum(i);
while(yy)
{
cout << "*";
yy--;
}
cout << endl;
}
xx--;
for(int i = xx; i >= 1; --i)
{
temp = xx - i+1;
while(temp)
{
cout << " ";
temp--;
}
yy = getNum(i);
while(yy)
{
cout << "*";
yy--;
}
cout << endl;
}
}