Nepal's open education portal

EduNepalEduNepal
Short5 marksmediumSolution

What is recursion? Write a recursive function in C to calculate the factorial of a positive integer.

C Programming

Verified Solution & Step-by-Step Explanation

solution · en · Verified by Editorial Board

Recursion in C

Recursion is a programming technique where a function calls itself directly or indirectly to solve smaller sub-problems of the same type until a termination condition (base case) is satisfied.

```c #include <stdio.h>

long long factorial(int n) { // Base Case if (n <= 1) return 1; // Recursive Case return n * factorial(n - 1); }

int main() { int num = 5; printf("Factorial of %d is: %lld\n", num, factorial(num)); return 0; } ```