#!/usr/bin/env ruby # # iFactorial0.rb # # Victor Hanson-Smith (with mods by Steve Fickas) # QUESTIONS? -> {victorhs,fickas}@cs.uoregon.edu # # This Ruby script iteratively computes the factorial of an integer. # def fact(n) if n < 0 puts "factorial is undefined for negative numbers\n" exit #crashes the program end if n == 0 return 1 else result = 1 while (n > 0) result = result * n n = n-1 end return result end end