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..

Printable View

- 12-09-2010, 09:53 PMBgreen7887Pascals 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, 12:13 AMZack
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, 02:48 AMal_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, 05:37 AMZack
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, 05:10 PMBgreen7887
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;

- 12-10-2010, 06:57 PMJosAH
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, 12:22 AMal_Marshy_1981