Factorial of a number in Ruby

  1. A.Factorials are very simple things. They're just products, indicated by an exclamation mark. For instance, "four factorial" is written as "4!" and means 1×2×3×4 = 24. In general, n! ("n factorial") means the product of all the whole numbers from 1 to n; that is, n! = 1×2×3×...×n.
  2. Factorial of a number in Ruby
#!/usr/bin/ruby
puts "Enter a Number"
n=gets.to_i
fact=1
for i in 1..n
fact=fact*i
end
puts fact.

Out put:
Enter a Number
5
120

Comments

Popular posts from this blog

Php Form validation with Error messages with Checking fields.

Simple calculator using JQuery and HTML..

how to customize dashboard in active admin gem in rails 4