cours0708/P5B/ruby/exercices/fact_iterareur.rb

17 lines
164 B
Ruby
Raw Normal View History

2008-11-25 21:11:16 +00:00
def each_fact(n)
res = 1
for i in 0 .. n
res = res * i unless i == 0
yield(res)
end
res
end
res = 0
each_fact(10) do | i |
res = res + i
end
puts res