Created
March 19, 2013 05:24
-
-
Save chiragmongia/5193888 to your computer and use it in GitHub Desktop.
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
| def fact(n) | |
| if n == 0 | |
| 1 | |
| else | |
| n * fact(n-1) | |
| end | |
| end | |
| def pascal_row(n) | |
| for k in 0..n | |
| yield(fact(n)/(fact(k)*fact(n-k))) | |
| end | |
| end | |
| def pascal(no_of_row) | |
| for k in 0..no_of_row | |
| pascal_row(k) {|x| print "#{x}"} | |
| print "\n" | |
| end | |
| end | |
| print "Number of rows for Pascal's triangle: " | |
| row = gets.to_i | |
| pascal(row) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment