Factorial Using Recursion
📖 Scenario: Imagine you want to calculate the factorial of a number, which is the product of all positive integers up to that number. For example, factorial of 5 is 5 x 4 x 3 x 2 x 1 = 120.Using recursion, a function can call itself to solve smaller parts of the problem until it reaches the simplest case.
🎯 Goal: You will build a C program that calculates the factorial of a given number using a recursive function.
📋 What You'll Learn
Create a recursive function called
factorial that takes an integer n and returns the factorial of n.Use a base case in the recursion where factorial of 0 is 1.
Call the
factorial function with the number 5 and store the result.Print the result in the format:
Factorial of 5 is 120.💡 Why This Matters
🌍 Real World
Calculating factorial is useful in mathematics, statistics, and computer science problems like permutations and combinations.
💼 Career
Understanding recursion is fundamental for many programming tasks and technical interviews.
Progress0 / 4 steps