Menu
Coddy logo textTech

Recap - Factorial

Part of the Fundamentals section of Coddy's Ruby journey — lesson 43 of 88.

challenge icon

Challenge

Easy

Read a number n from input. Calculate the factorial of n using a loop and print the result.

Remember that the factorial of n (written as n!) is the product of all positive integers from 1 to n.

The input will be a single positive integer.

For example, if the input is 5, the output should be:

120

If the input is 7, the output should be:

5040

Try it yourself

# Read input
n = gets.to_i

# TODO: Write your code below to calculate the factorial of n


# Output the result
puts factorial

All lessons in Fundamentals