#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"); }
本文出自 “Vs吕小布” 博客,请务必保留此出处http://survive.blog.51cto.com/10728490/1703130
原文地址:http://survive.blog.51cto.com/10728490/1703130