Factorial

Factorial

Tags: Loops Basics

Credit: CodingChallenge

Difficulty: Beginner

Type: Text

Category: Practice

Time Allowed: 5 s

Description:

Write a function that takes a positive integer N and returns its factorial calculated using a for loop. This problem is designed to help you practice using for loops for calculations. The function should accept one parameter and return the factorial.

Constraints:

  • The input will be a positive integer greater than or equal to zero.
  • The factorial of 0 is 1.
  • The function should return an integer representing the factorial of N.

Example:

  • Input: 5
  • Output: 120 // Explanation: 5! = 5 * 4 * 3 * 2 * 1 = 120

Test Case Input Expected Output
1 0 1
2 1 1
3 5 120
4 7 5040
5 3 6

Please register or login to submit solutions to challenges.