qq_浮梦壹生_03287462
#include <stdio.h>int main() { int i,j; int a[10][10]; printf("\n"); for(i=0;i<10;i++) { a[i][0]=1; a[i][i]=1; } for(i=2;i<10;i++) for(j=1;j<i;j++) a[i][j]=a[i-1][j-1]+a[i-1][j]; for(i=0;i<10;i++) { for(j=0;j<=i;j++) printf("%5d",a[i][j]); printf("\n"); } return 0;} 再来个java语言的int[] triangle=null; int[] tmp=null; for (int i=0;i<10;i++){ if(i==0){ tmp = new int[1]; tmp[0]=1; } else if (i==1){ tmp = new int[3]; tmp[0] = 1; tmp[1] = 2; tmp[2] = 1; }
else { tmp=new int [i+2]; tmp[0]=1; for(int j=1;j<i+1;j++){ tmp[j]=triangle[j-1]+triangle[j]; } tmp[tmp.length-1]=1; } triangle=tmp; for(int j=0;j<triangle.length;j++){ System.out.print(tmp[j]); System.out.print(" "); } System.out.println(); }