Created
February 5, 2012 13:48
-
-
Save sassy/1745669 to your computer and use it in GitHub Desktop.
rustでpascal's 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
| use std; | |
| fn factorial(n: int) -> int { | |
| if n == 0 {ret 1; } | |
| else {ret n * factorial(n - 1); } | |
| } | |
| fn bt(n: int, k: int) -> int { | |
| ret factorial(n) / (factorial(n -k) * factorial(k)); | |
| } | |
| fn pascal(k: int) { | |
| let i = 0; | |
| while i <= k { | |
| let j = 0; | |
| while j <= i { | |
| std::io::print(int::str(bt(i, j)) + " "); | |
| j += 1; | |
| } | |
| std::io::println(""); | |
| i += 1; | |
| } | |
| } | |
| fn main() { | |
| pascal(6); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment