方法一:
#include <iostream> using namespace std; int main() { int row; cout << "请输入倒金字塔的行数:"; cin >> row; for (int i = row; i >= 1; i--) { for (int k = i; k <= row-1; k++) { cout << " "; } for (int n = 1; n <+ 2 * i; n++) { cout << "*"; } cout << endl; } system("pause"); return 0; }

 

方法二:
#include <iostream>
using namespace std;
int main() {
    int row;
    cout << "请输入倒三角的行数:";
    cin >> row;

    for (int i = 1; i <= row; i++) {
        for (int k = 0; k < i - 1; k++) {
            cout << " ";
        }
        for (int n = 2 * row - 2 * i + 1; n > 0; n--) {
            cout << "*";
        }
        cout << endl;
    }
    system("pause");
    return 0;
}

 

 

posted on 2022-08-12 22:56  wshidaboss  阅读(1045)  评论(0编辑  收藏  举报