Thread: Pascal triangle numbers generation~

  1. #1
    Registered User bljonk's Avatar
    Join Date
    Oct 2001
    Posts
    70

    Pascal triangle numbers generation~

    I've been unsuccessfully trying to write a program to generate pascal triangle numbers and insert them into an 2D flexible array, but i still not getting it; any sugestions?
    Last edited by bljonk; 03-21-2002 at 03:28 PM.

  2. #2
    Registered User
    Join Date
    Nov 2001
    Posts
    162
    The formula for a Pascal Triangle element is:
    Code:
       n!
    --------
    r!(n-r)!
    Whereas n is the row and r is the element(left to right). ! is a factoral sign, which means to multiply that number times every number below it to 1. Like: 6! = 6*5*4*3*2*1 = 720. Puting this in code shouldn't be too hard. Putting it in an array sounds easy, because you could just take a two dimention array and have the row and element as the array subscript numbers. If you still need some coding help just reply back.

  3. #3
    Blank
    Join Date
    Aug 2001
    Posts
    1,034
    Another way to generate pascal's numbers is to look at

    1
    1 2 1
    1 3 3 1
    1 4 6 4 1

    Look at the 4 and the 6. It is clear that
    4 = 1 + 3
    6 = 3+3

    Every number in pascal's triangle except for the boundary 1's are such that
    pascal(row, col) = pascal(row-1, col-1) + pascal(row-1, col). You can implement a straitforward recursive soultion or by using the array not need recursion.

  4. #4
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145

    Observe

    Just observe that 0! = 1, and not 0
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  5. #5
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,380
    >2D flexible array

    A 2D flexible array?

  6. #6
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    Originally posted by Shiro
    >2D flexible array

    A 2D flexible array?
    He probably means dynamic, it should be larger the higher number he inputs.

    PS: How do you represent pascals triangle in a "square" 2D array? hmmmmmmmm...

  7. #7
    Registered User bljonk's Avatar
    Join Date
    Oct 2001
    Posts
    70
    Thanks that's all i needed to know

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Logical errors with seach function
    By Taka in forum C Programming
    Replies: 4
    Last Post: 09-18-2006, 05:20 AM
  2. Just in case: "Odd" Triangle Challenge (for me)
    By BB18 in forum C Programming
    Replies: 3
    Last Post: 10-09-2004, 12:02 AM
  3. pascal triangle
    By ndukaa1 in forum C++ Programming
    Replies: 15
    Last Post: 10-05-2004, 10:40 PM
  4. the definition of a mathematical "average" or "mean"
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 7
    Last Post: 12-03-2002, 11:15 AM
  5. Pascal Triangle
    By Unregistered in forum C++ Programming
    Replies: 2
    Last Post: 02-22-2002, 01:34 PM