C语言:输出杨辉三角形前n行
#include <stdio.h> #define N 10 main() { int shu[N][N]={0},a,b,c; for(a=0;a<N;a++) { for(c=N-1-a;c>=0;c=c-1) printf(" ") ; for(b=0;b<=a;b++) { shu[a][b]=1; if(!(a==0 || a==b)) shu[a][b]=shu[a-1][b-1]+shu[a-1][b]; printf("%3d ",shu[a][b]); } printf("\n"); } getchar(); }