Can we generate a Pascal's Triangle using a one dimensional array (in Java/C++) ?

1 Answer

  • 1 decade ago
    Favourite answer


    1. Create an array with N elements. Visualize it as going from left to right. Load the left-most element with '1'. Load everything else with '0'

    2. Print the array

    3. Loop throough the array, going from right to left (N-1 ... I ... 0)

    3a. Add the I element to the I+1 element. Store the result in the I element

    3b. If (I < N-2) goto 3a. Else, exit the loop

    4. Goto step 2

    This should do the trick

    • Commenter avatarLog in to reply to the answers
Still have questions? Get answers by asking now.