In the constructor, when initializing the 2D array, in the else
, your assignment is incorrect. You want to initialize the current element, but the left hand side is incorrect (and inconsistent with the if
):
pascal[x-1][y-1] = pascal[x-1][y] + pascal[x-1][y-1];
Try the [x][y]
element itself.
pascal[x][y] = pascal[x-1][y] + pascal[x-1][y-1];
Making only this change, I get the correct output:
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1