posts - 137,comments - 0,views - 40818
复制代码
#include <iostream>
#include <windows.h>
#include <string>
using namespace std;
void test(int n,char ch='$') {   //可以在此指定默认参数
    for (int i = 1; i <= n; i++) {   
        for (int y = 0; y < n - i; y++) {
            cout << " ";
        }
        for (int x = 1; x <= 2 * i - 1; x++) {
            cout << ch;
        }
        cout << endl;
    }
}
int main() {
    int i;
    char ch;
    cout << "请输入金字塔的层数:";
    cin >> i;
    cout << "请输入金字塔的符号:";
    cin >> ch;

    test(i,ch);   //也可在此输入指定的符号

    system("pause");
    return 0;
}
复制代码

 

posted on   wshidaboss  阅读(208)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· winform 绘制太阳,地球,月球 运作规律
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· AI 智能体引爆开源社区「GitHub 热点速览」
· 写一个简单的SQL生成工具
· Manus的开源复刻OpenManus初探
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

点击右上角即可分享
微信分享提示