Short5 marksmediumSolution
What is recursion? Write a recursive function in C to calculate the factorial of a positive integer.
C Programming
Nepal's open education portal — School, +2, Diploma, Bachelor & Master in one place
solution · en · Verified by Editorial Board
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; } ```