View Code of Problem 53

#include<iostream>
using namespace std;

int main()
{
    int n;
    while (1)
    {
        cout << "输入一个数n\n";
        cin >> n;
        if (n > 9 || n < 1)
        {
            cout << "输入数据不在要求范围内\n";
            return 0;
        }
        for (int i = 1; i <= n; i++)
        {
            for (int j = 1; j < n; j++)
            {
                cout << " ";
            }
            for (int j = 0; j < n - i; j++)
            {
                cout << " ";
            }
            for (int j = 0; j < 2 * i - 1; j++)
            {
                cout << "*";
            }
            cout << endl;
        }
        for (int i = 1; i <= n - 1; i++)
        {
            for (int j = 0; j < n - 1; j++)
            {
                cout << " ";
            }
            for (int j = 1; j < i + 1; j++)
            {
                cout << " ";
            }
            for (int j = 1; j <= 2 * n - 1 - 2 * i; j++)
            {
                cout << "*";
            }
            cout << endl;
        }
    }
    return 0;
}

Double click to view unformatted code.


Back to problem 53