index | submit | rank | book

factorial1 – Factorial of a number (easy version)

Write a program that computes the factorial of a number n, or simply n!.

Factorial of 0, 1, 2, 3, and 4 represented graphically.

We can recursively define the factorial of a number as:

In symbolic terms:

By the above definition, the factorial of 4 is 24

Input and Output

Input will contain a single integer n where 0 ≤ n < 10. Output should contain a line with the factorial of n.

Example input 1


Example output 1


Example input 2


Example output 2


The factorial function

Your program should contain a factorial function that takes an integer and returns an integer. Please refer to the information for your chosen language:

Specifically for this exercise when using Python, JavaScript, Lua or Ruby, avoid using sys.exit(), process.exit(), os.exit() or exit, as your program is appended with some extra assertions in one of the test sets.


try first: good1 signum1

try next: power1

index | submit | rank | book

Copyright © 2020-2023 Rudy Matela
All rights reserved