04-17-2006, 05:05 PM
Can anyone help me in forming a pascal triangle?
This is what i got so far, i've only been able to show a specific row,
the formula for calculating an element in pascal triangle is
nCr = n!/ r!(n-r)!
n is the number of row
r is the element we're looking for
In my code :
n is n
n! is j
r! is k
(n-r)! is m
and x is to show elements containing in n row
my question is, how do i repeat this process from 1 to n?
so if i input 5, it'd show
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
1 5 10 10 5 1
instead of just "1 5 10 10 5 1" like my program does
i've tried using for next and do while, but it still doesn't work.. help anyone?
This is what i got so far, i've only been able to show a specific row,
the formula for calculating an element in pascal triangle is
nCr = n!/ r!(n-r)!
n is the number of row
r is the element we're looking for
In my code :
n is n
n! is j
r! is k
(n-r)! is m
and x is to show elements containing in n row
Code:
DIM r AS STRING
CLS
INPUT "Enter the number of row"; n
IF n = 0 THEN
PRINT 1
GOTO 1
END IF
j = 1
DO
i = i + 1
j = j * i
LOOP UNTIL i = n
PRINT
PRINT 1;
k = 1
DO
l = l + 1
k = k * l
m = 1
FOR g = n - l TO 1 STEP -1
m = m * g
NEXT g
x = j / (k * m)
PRINT x;
LOOP UNTIL l = n
PRINT 1
1 END
my question is, how do i repeat this process from 1 to n?
so if i input 5, it'd show
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
1 5 10 10 5 1
instead of just "1 5 10 10 5 1" like my program does
i've tried using for next and do while, but it still doesn't work.. help anyone?