Ruby program to find factorial of a given number
=begin
Ruby program to find the factorial of a given number.
=end
puts "Enter the number:"
num=gets.chomp.to_i
fact=1
if (num==0)
puts "Error! Could not find the factorial of one"
else
i=1
while(i<=num)
fact=fact*i
i+=1
end
end
puts "factorial of #{num} is #{fact}"
Output:
Run 1:
Enter the number:
5
factorial of 5 is 120
Run 2:
Enter the number:
7
factorial of 7 is 5040
