this code gives an error.Can u tell me where is the error in that code?
Doubt in pascal's Triangle
@Tanish
Could you please specify which of these two questions are you trying ?
Both of these are for Pascal Triangle pattern and the only difference is in spacing.
1 - https://hack.codingblocks.com/contests/c/916/53
2 - https://hack.codingblocks.com/contests/c/239/364
Also your code is not giving an error but rather wrong outputs. Your code shows negative values on the right and is missing the first column of ones on the left.
Pascal triangle isn’t just a pattern with counting. You have to add the terms above the current term to get the current term. Your output seems entirely wrong. I suggest you to make some modifications in your current approach regarding these problems or try an alternate approach.
Here are some suggestions :
- Use an array to store the values and you can simply add the above terms from the previous row to compute the next element.
- Alternatively you can use this formula to compute the next value without array.
value = value * (i - j) / j;
where value is initialised as 1 in the beginning before the loops start . i represents row number and j represents column number
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.