Advertisement
d1i2p3a4k5

1.pascal triangle

Oct 18th, 2014
276
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.70 KB | None | 0 0
  1. import java.util.*;
  2. import java.lang.*;
  3. class pascal
  4. {
  5.     public static void main(String args[])
  6.     {
  7.         int i,j,k,n;
  8.         Scanner t = new Scanner(System.in);
  9.         System.out.println("n = ?");
  10.         n = t.nextInt();
  11.         System.out.println("PASCAL TRIANGLE FOR "+n+" no. of lines is below ");
  12.             for(i=0;i<n;i++)
  13.             {
  14.                 for(j=n-i;j>0;j--)
  15.                 {
  16.                     System.out.print(" ");
  17.                 }
  18.                 for(k=0;k<=i;k++)
  19.                 {
  20.                     int z = comb(i,k);
  21.                     System.out.print(z+"  ");
  22.                 }
  23.                 System.out.println("");
  24.             }
  25.        
  26.        
  27.     }
  28.    
  29.     static int fact(int x)
  30.     {
  31.         if(x==0)
  32.            
  33.             return 1;
  34.         else return x*fact(x-1);
  35.     }
  36.     static int comb(int x,int y)
  37.     {
  38.         int z;
  39.         z = fact(x)/(fact(x-y)*fact(y));
  40.         return z;
  41.     }
  42.    
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement