以下是使用C语言编写的代码,可以打印出10行的杨辉三角形:

#include <stdio.h>

int main() {
    int rows = 10;

    int triangle[rows][rows];

    for (int i = 0; i < rows; i++) {
        for (int j = 0; j <= i; j++) {
            if (j == 0 || j == i) {
                triangle[i][j] = 1;
            } else {
                triangle[i][j] = triangle[i-1][j-1] + triangle[i-1][j];
            }

            printf("%d ", triangle[i][j]);
        }
        printf("\n");
    }

    return 0;
}

运行该代码,将会打印出10行的杨辉三角形。

用C语言编辑可运行代码实现以下功能 打印出以下杨辉三角要求打印出10行。

原文地址: https://www.cveoy.top/t/topic/hDGD 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录