Factorial of a number in Ruby

Ruby code to find the Factorial of a given number

Source code :


number = 5; # Change the number here 

fact = 1;

(1..number).each do |i|
    fact = fact*i;
end

print "Factorial of ", number ," is: ", fact




Output :

Factorial of 5 is: 120

Output :


                

Comments :