In this Ruby example to calculate factorial of a number we are using while loop puts "Enter the number" i = 1 while i <= num #implementation of while loop puts "The factorial of #{num} is #{fact}" Output Enter the number
num=gets.chomp.to_i
fact = 1
fact *= i
i += 1
end
5
The factorial of 5 is 120
How to get index of array element in Ruby
What's the difference between a lambda, a block and a proc?
How to add/remove elements to Array in Ruby?
What are the various Ruby runtimes, and how are they different?
Ruby program to add two integer numbers
Creating Array with Array.new(size, obj) in Ruby
What are some of your favorite gems? What are their alternatives?
How to Get Input with Gets in Ruby
Ruby program to Calculate the factorial of given number
Ruby program to reverse a string
Ruby program to check whether the given number is prime or not
Ruby program to generate random numbers
Ruby program to print Fibonacci series
Ruby program to check whether the given number is Armstrong
What are #method_missing and #send? Why are they useful?
Program to Print Triangle of Numbers in Ruby
How to shuffle an array in Ruby?
how to create an array with Array.[](*args) in Ruby ?
How to Sort Array in Ruby?
Ruby program to check whether the given number is palindrome
How to create two dimensional array in ruby?
Ruby program to print an array
How to Replace array elements in Ruby?