Factorial in Ruby
Example for versions
Ruby 1.9
This example uses an iterative factorial definition
def fact(n)
(1..n).reduce(:*)
end
(0..16).each {|x| puts "#{x}! = #{fact(x)}"}
Comments
]]>blog comments powered by Disqus
]]>