#!/usr/bin/env ruby # # rFactorial.rb # # Victor Hanson-Smith # QUESTIONS? -> victorhs@cs.uoregon.edu # # This Ruby script recursively computes the factorial of an integer. # def fact(n) if n < 0 puts "factorial is undefined for negative numbers\n" exit end if n == 0 1 else return n * fact(n-1) end end # Ensure that command-line arguments exist: if (ARGV.length < 1) puts "\n Usage: rFactorial \n" else # compute the factorial: result = fact(ARGV[0].to_i) # display the results puts result end