Created
June 14, 2011 02:55
-
-
Save iporsut/1024215 to your computer and use it in GitHub Desktop.
Print Pascal Triangle
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class PascalTriangle { | |
public static long fact(long n) { | |
if (n == 0) | |
return 1; | |
if (n == 1) | |
return 1; | |
long f = 1; | |
for (long i = 2; i <= n; i++) { | |
f *= i; | |
} | |
return f; | |
} | |
public static long comb(long n, long r) { | |
return fact(n) / (fact(r)*fact(n-r)); | |
} | |
public static void main(String []args) { | |
System.out.print("Insert input : "); | |
int input = Integer.valueOf((System.console()).readLine()); | |
for (int i = 0; i < input; i++) { | |
for (int s = input-1; s > i; s--) | |
System.out.print(" "); | |
for (int j = 0; j <= i; j++) { | |
System.out.print(comb(i,j) + " "); | |
} | |
System.out.println(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment