answersLogoWhite

0

Pascal's triangle using q-basic

Updated: 11/2/2022
User Avatar

Wiki User

14y ago

Best Answer

You could just use the binomial theorem. Step through rows, n, and entries, k, and compute the Pascal's triangle value as

n!/(k!*(n-k)!)

You'll actually have better luck if you use the natural log of a factorial, then you can use laws of exponents to get:

exp(log(n!/k!/(n-k)!))

= exp(log(n!)-log(k!)-log((n-k)!))

= exp(logfact(n)-logfact(k)-logfact(n-k))

which won't run into the integer overflow problems that a plain factorial function would have.

To fill up a logfact array, something like this might work:

while(i<maxn)

logfact(i)=logfact(i-1)+log(i)

i=i+1

Wend

Be careful to initialize correctly, and watch your conversion between integers and doubles (probably have to do some rounding to your final answers).

User Avatar

Wiki User

14y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Pascal's triangle using q-basic
Write your answer...
Submit
Still have questions?
magnify glass
imp