What does the current code do? What is wrong with the results?
Show the output and explain/show what it should be.
NormR1
Posting Expert
6,677 posts since Jun 2010
Reputation Points: 1,138
Solved Threads: 656
NormR1
Posting Expert
6,677 posts since Jun 2010
Reputation Points: 1,138
Solved Threads: 656
What you need to do is to think about how you really build a pascal triangle manually before you can implement in a code. Your current code has flaws.
1) You do not need to create 2D array to accommodate a triangle. If you look at it, about half of the memory space you acquire for your variable is used, and the other half is empty. A dynamic array would be OK.
2) You could either build and save all value of the triangle, or keep value only the previous and current rows you are working on. The easiest way is to keep all in a dynamic array, such as ArrayList.
3) In each row, you need to compute the added value from the previous row up to half of the row. The other half, you just copy it in reverse order.
4) Do not attempt to find out the problem's result value until you can complete building your triangle.
5) Do not forget that you need to build 1 more row from whatever a user specifies in order to compute the total value of the "after" row.
Hope this help you to think a bit further. Please get back with some code you implement with more of your thought.
Taywin
Posting Virtuoso
1,727 posts since Apr 2010
Reputation Points: 229
Solved Threads: 239