pascal's Triangle implementation

后端 未结 2 1612
没有蜡笔的小新
没有蜡笔的小新 2020-12-22 05:53

I am trying to make a program for pascal\'s triangle,the formaula to calculate the rth value in nth row is n!/r!(n-r)!

I\'ve b

2条回答
  •  悲&欢浪女
    2020-12-22 06:42

    The very first thing you've gone wrong at is the formatting of your code. It's horrible. (Sorry, it really is.)

    The second thing is that you are always printing Pascal(r, n) whereas they are constant 0, 0 - you should print Pascal(i, j) instead, since i and j are the loop counters.

    By the way, you'd be better off calculating the factorials iteratively and using long enough integers, your code threw SIGXCPU on IDEOne and segfaulted on my computer.

提交回复
热议问题