Pascal Triangle


/ Published in: Java
Save to your folder(s)



Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.