杨辉三角
#include <stdio.h> #include <stdlib.h> #define N 10 void main() { int a[N][N] = { 0 }; for (int i = 0; i < N; i++) { for (int j = 0; j < i+1; j++) { if (j == 0 || i == j) { a[i][j] = 1; } else { a[i][j] = a[i - 1][j - 1] + a[i - 1][j]; } } } for (int i = 0; i < N; i++) { for (int k = 0; k < N - 1 - i; k++) { printf(" "); } for (int j = 0; j < i+1; j++) { printf("%4d", a[i][j]); } printf("\n"); } system("pause"); }