C语言复习---杨辉三角打印
#define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include <stdlib.h> #include <math.h> #define MAX 8 int main() { int a[MAX][MAX] = { 0 }; for (int i = 0; i < MAX; i++) { a[i][0] = 1; a[i][i] = 1; if (i>=2) for (int j = 1; j < i; j++) a[i][j] = a[i - 1][j - 1] + a[i - 1][j]; } for (int i = 0; i < MAX; i++) { for (int j = 0; j < MAX; j++) if (a[i][j] != 0) printf("%5d", a[i][j]); printf("\n"); } system("pause"); return 0; }