public static void PascalTriangle(int lines){
int [][] triangle ;
triangle= new int [lines][lines];
for (int lineIndex = 0 ; lineIndex < lines ; lineIndex++){
for (int col = 0 ; col < lineIndex ; col++) {
if ( (col == 0) || (col == lineIndex - 1 ) ) {
// First and last element in Pascal's triangle is always 1.
triangle[lineIndex][col] = 1 ;
} else {
if (lineIndex != 0 ) triangle[lineIndex][col] = triangle[lineIndex-1][col-1] + triangle[lineIndex-1][col];
}
System.out.print(" " + triangle[lineIndex][col] );
}
System.out.println();
}
}
This blog is to say Hello to the world of Blogs :) Yeah, now i am going to get my thoughts across to you people out there even faster and efficient way. Hope you find this helpful and interesting.. Keep Blogging :)
Sunday, October 08, 2006
Pascal's Traingle w/o formula.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment