Posted By

hotou on 02/04/10


Tagged


Versions (?)

Pascal Triangle


 / Published in: Java
 

  1. public static int[][] pascal(int n) {
  2. int[][] res = new int[n+1][n+1];
  3.  
  4. for (int i = 0; i <= n; i++) {
  5. res[i][0] = 1;
  6. }
  7.  
  8. for (int i = 0; i <= n; i++) {
  9. for (int j = i; j > 0; j--) {
  10. res[i][j] = res[i-1][j-1] + res[i-1][j];
  11. }
  12. }
  13.  
  14. return res;
  15. }

Report this snippet  

You need to login to post a comment.