answersLogoWhite

0

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

15y ago

Still curious? Ask our experts.

Chat with our AI personalities

RossRoss
Every question is just a happy little opportunity.
Chat with Ross
CoachCoach
Success isn't just about winning—it's about vision, patience, and playing the long game.
Chat with Coach
MaxineMaxine
I respect you enough to keep it real.
Chat with Maxine

Add your answer:

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