Menu
Coddy logo textTech

Factorial

Lesson 15 of 32 in Coddy's Coding Problems course.

Factorial (!), in mathematics is the product of all positive integers less than or equal to a given positive integer.

Create a program that will calculate the factorial of a given positive number.

challenge icon

Challenge

Medium

Write a function named factorial that given a natural number N from input. Output it's factorial to the screen

 

5! = 1 * 2 * 3 * 4 * 5 = 120

 

Input
5

Output
120

Input
7

Output
5040

Try it yourself

int factorial(int a1) {
    // Write code here
}

All lessons in Coding Problems