Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- import java.lang.*;
- class pascal
- {
- public static void main(String args[])
- {
- int i,j,k,n;
- Scanner t = new Scanner(System.in);
- System.out.println("n = ?");
- n = t.nextInt();
- System.out.println("PASCAL TRIANGLE FOR "+n+" no. of lines is below ");
- for(i=0;i<n;i++)
- {
- for(j=n-i;j>0;j--)
- {
- System.out.print(" ");
- }
- for(k=0;k<=i;k++)
- {
- int z = comb(i,k);
- System.out.print(z+" ");
- }
- System.out.println("");
- }
- }
- static int fact(int x)
- {
- if(x==0)
- return 1;
- else return x*fact(x-1);
- }
- static int comb(int x,int y)
- {
- int z;
- z = fact(x)/(fact(x-y)*fact(y));
- return z;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement