#include<stdio.h> int main() { int a[20][20] = { 0 }; int n = 0, i = 0, j = 0; printf("杨辉三角\n\n"); printf("请输入一个自然数:"); scanf_s("%d", &n); for (i = 0; i < n;i++) a[i][0] = 1; for (i = 1; i < n; i++) for (j = 1; j <= i; j++) { a[i][j] = a[i - 1][j - 1] + a[i - 1][j]; } for (i = 0; i < n; i++) { for (j = 0; j <= i; j++) printf("%5d", a[i][j]); printf("\n"); } system("pause"); }
时间: 2024-11-07 02:15:05