编辑代码

#include <iostream>

// 非递归地打印数值三角形
void printTriangleNonRecursively(int n) {
    for (int i = 1; i <= n; ++i) {
        // 打印当前数字 i 次
        for (int j = 0; j < i; ++j) {
            std::cout << i << " ";
        }

        std::cout << std::endl;
    }
}

int main() {
    int n;
    std::cout << "请输入 n 的值:";
    std::cin >> n;

    // 调用非递归函数打印数值三角形
    printTriangleNonRecursively(n);

    return 0;
}