summaryrefslogtreecommitdiff
path: root/sample/fact.rb
blob: 1462a6923ac2d412764e502ff6ccb65593897dd8 (plain)
1
2
3
4
5
6
7
8
9
10
def fact(n)
  return 1 if n == 0
  f = 1
  while n>0
    f *= n
    n -= 1
  end
  return f
end
print fact(ARGV[0].to_i), "\n"