int x[20]={0}; int y[20]={0}; int a;//层数 printf("请输入杨辉三角形的层数:"); scanf("%d",&a); int i,j,k; for(i=0;i<a;i++) { if(i == 0) { x[i]=1; y[i]=1; } for(j=0;j<=i;j++) { printf("%d ",y[j]); y[j+1]=x[j]+x[j+1]; if(j==i) y[j+1]=1; } for(k=0;k<=i;k++) x[k]=y[k]; printf(" ");
int i,j,a[11][11]; for(i=1;i<11;i++) { a[i][i]=1; a[i][1]=1; } for(i=3;i<11;i++) { for(j=2;j<=i-1;j++) { a[i][j]=a[i-1][j-1]+a[i-1][j]; } } for(i=1;i<11;i++) { for(j=1;j<=i;j++) { printf("%d ",a[i][j]); } printf(" "); }
int i,j,a[11][11]; for(i=1;i<11;i++) { a[i][i]=1; a[i][1]=1; } for(i=3;i<11;i++) { for(j=2;j<i;j++) { a[i][j]=a[i-1][j-1]+a[i-1][j]; printf("%d ",a[i-2][j-1]); } printf(" "); }