Solution in java ONLY plz... FULL question can be found on the following link http://ntci.on.ca/compsci/java/ch5/5_9.html ---> question 14
Thanks, appreciate it
I cannot put full question here as its too long... so full question is on the link
----------------------------------------------------------------------------------
Write a program that prints portions of Pascal's triangle. The program should repeatedly ask the user to supply the number of rows in the triangle, terminating when the user supplies the value zero. In printing a triangle, the first value in the last row should appear in the first column and each preceding row should start printing three spaces further right........
import java.io.*;
class GFG {
public int factorial(int i)
{
if (i == 0)
return 1;
return i * factorial(i - 1);
}
public static void main(String[] args)
{
int n = 4, i, j;
GFG g = new GFG();
for (i = 0; i <= n; i++) {
for (j = 0; j <= n - i; j++) {
System.out.print(" ");
}
for (j = 0; j <= i; j++) {
System.out.print(
" "
+ g.factorial(i)
/ (g.factorial(i - j)
* g.factorial(j)));
}
System.out.println();
}
}
}
Comments
Leave a comment