summaryrefslogtreecommitdiff
path: root/sample/fact.rb
blob: 9f6ca72ca7607976c543df8e65021ef1aa70321f (plain)
1
2
3
4
5
6
7
8
9
def fact(n)
  return 1 if n == 0
  f = 1
  n.downto(1) do |i|
    f *= i
  end
  f
end
puts fact(ARGV[0].to_i)