带着学一下打印这道题呗

img


#include <iostream>
using namespace std;
int main()
{
    int n;
    cin >> n;
    for(int i = 0; i < n; i++)
    {
        for(int j= 0; j<i; j++)
        {
            cout << " ";
        }
        cout << "*";
        for(int k = 0; k < 2*(n-i)-3; k++)
        {
            cout << " ";
        }
        if(i==0)
        {
            cout << "*";
        }
        else if(i==(n-1))
        {


        }
        else
        {
            cout << "*";
            for(int m = 0; m < 2*i-1; m++)
            {
                cout << " ";
            }
            cout << "*";
        }
        for(int k = 0; k < 2*(n-i)-3; k++)
        {
            cout << " ";
        }
        if(i==(n-1))
        {
            for(int k = 0; k < 2*(n)-3; k++)
            {
                cout << " ";
            }
        }
        cout << "*";
        cout << endl;
    }
    return 0;
}