summaryrefslogtreecommitdiff
path: root/ruby_1_8_5/sample/fact.rb
diff options
context:
space:
mode:
Diffstat (limited to 'ruby_1_8_5/sample/fact.rb')
-rw-r--r--ruby_1_8_5/sample/fact.rb9
1 files changed, 9 insertions, 0 deletions
diff --git a/ruby_1_8_5/sample/fact.rb b/ruby_1_8_5/sample/fact.rb
new file mode 100644
index 0000000000..d8147a40f1
--- /dev/null
+++ b/ruby_1_8_5/sample/fact.rb
@@ -0,0 +1,9 @@
+def fact(n)
+ return 1 if n == 0
+ f = 1
+ n.downto(1) do |i|
+ f *= i
+ end
+ return f
+end
+print fact(ARGV[0].to_i), "\n"