diff options
Diffstat (limited to 'jni/ruby/sample/fact.rb')
-rw-r--r-- | jni/ruby/sample/fact.rb | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/jni/ruby/sample/fact.rb b/jni/ruby/sample/fact.rb new file mode 100644 index 0000000..d8147a4 --- /dev/null +++ b/jni/ruby/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" |