import java.util.Scanner; public class pascal { static int fact(int t) { if(t==1 || t==0) return 1; else return t*fact( t - 1 ); } public static void main(String[] args) { Scanner sc=new Scanner(System.in); System.out.println("Enter the no of rows:"); int n=sc.nextInt(); int i,j; for (i = 0; i <= n; i++) { for (j = 0; j<= (n - i - 2); j++) System.out.print(" "); for (j = 0 ; j <= i; j++) { int x=(fact(i)/(fact(j)*fact(i-j))); System.out.print(x+ " "); } System.out.println(); } } } Example of Pascal Triangle---
No comments:
Post a Comment