Board index » delphi » Pascal triangle

Pascal triangle

Quote
Esky wrote:
> I am going to write a program, using two-dimensional array, to print
> out
> a Pascal triangle

> The method that I consider to use will be the easiest one, that is add

> up the two numbers immediately above it (the two edges of  the
> triangle
> are occupied by 1 of course), not by using nCr and factorial, or
> something like that.
> For me, I am just a beginner of programming, I need some examples on
> two
> dimensional array, any website or hint?

     I like your idea of doing it "the easy way" by adding the numbers
directly above, but don't understand why you need to know about 2-D
arrays.  Suppose I reformulate the
problem slightly.  I'll define "PascalTriangle (row, column)" as the
number in row, column, with the rules that column <= row, both are >= 1,
the outer entries are all 1, and the rule
you state applies.  I maintain that if you code this directly as a
function (it will be recursive, of course), you'll get an extremely
simple, actually quite fast, expression for Pascal's Triangle.  [As a
side benefit, for larger numbers of rows and columns, it won't have the
danger of overflows that a naive implementation of the factorial method
might exhibit].

Bob Schor
Pascal Enthusiast

 

Re:Pascal triangle


I am going to write a program, using two-dimensional array, to print out
a Pascal triangle

          1
        1   1
      1   2   1
    1   3   3   1
  1   4   6   4   1
1   5  10  10   5   1

just like this one.

The method that I consider to use will be the easiest one, that is add
up the two numbers immediately above it (the two edges of  the triangle
are occupied by 1 of course), not by using nCr and factorial, or
something like that.
For me, I am just a beginner of programming, I need some examples on two
dimensional array, any website or hint?
Thanks in advance.

Esky

Other Threads