# Pascals Triangle

• 12-09-2010, 10:53 PM
Bgreen7887
Pascals Triangle
Guys can anyone help get me started somehow on going about how to write this. DESIGN AND IMPLEMENT A RECURSIVE METHOD TO DISPLAY THE NTH LINE OF PASCALS TRIANGLE. the only thing i can think is that i need an array to store each line..
• 12-10-2010, 01:13 AM
Zack
Work it out on paper. Pick a number (like 5 or 6), and draw every line of Pascal's Triangle up to that point. Then think about how you determined each line in your head. Think about the criteria you use to determine which numbers would go in which order.
• 12-10-2010, 03:48 AM
al_Marshy_1981
Or to help out those who do not know post a description of what Pascal's Triangles are...so we can help you programmatically (is that a word :D)
• 12-10-2010, 06:37 AM
Zack
Quote:

Originally Posted by al_Marshy_1981
Or to help out those who do not know post a description of what Pascal's Triangles are...so we can help you programmatically (is that a word :D)

Silly guy--never took math!? =) Clicky.

The numbers are based on binomial theorem; it is formulated as such, and procedurally generated by adding adjacent numbers for the row below.
• 12-10-2010, 06:10 PM
Bgreen7887
Hey guys thanks for the responses i've been away so i couldnt reply..UGGHH.. ok so i've wrote a little bit of code but im basically shooting in the dark ..heres what i have so far..Code has some english in it so please dont critique TOO MUCH , im trying.
Code:

``` public class Pascal {         public static void main(String[] args) {                          Pascal p=new Pascal();         int row=10;         for(int x=0;x<=row;x++){             for(int y=0;y<=x;y++){                             System.out.print(p.pascal(x, y)+" ");                                         System.out.println();             }                                 }                                 }                 int pascal(int x,int y) {       if(x=1 || x=y || y=0){       }       else{             return pascal(x-1,y-1)+pascal(x-1,y);       } } } //int x=row; //int y=col;```
i will start over if suggested if this code is completly bogus, i know its a mathematical pattern but im having trouble with all the loops and dont no if i should just use an array..i need to code this and understand it before my final pretty sure its going to be on there..using recursion...THANKS MATES
• 12-10-2010, 07:57 PM
JosAH
Suppose you have the values for n-1, say, 1, 3, 3, 1. For the values for row n all you have to do is add all (left) consecutive values from the right: 1, 4, 6, 4 and add another value 1 to the right: 1, 4, 6, 4, 1. For n == 0 you have the value 1 and you don't need to know more.

kind regards,

Jos
• 12-16-2010, 01:22 AM
al_Marshy_1981
Quote:

Originally Posted by Zack
Silly guy--never took math!? =) Clicky.

The numbers are based on binomial theorem; it is formulated as such, and procedurally generated by adding adjacent numbers for the row below.

Boy if I got serious about math I'd be half decent :D thanks for the links