/*Recursion is a programming technique where a function calls itself either
directly or indirectly. It involves breaking down a larger problem into 
smaller, more manageable subproblems until a base case is reached.*/

#include <stdio.h>

unsigned int factorial(unsigned int n) {
   if (n == 0)
      return 1;
   else
      return n * factorial(n - 1);//-> 5 * fact(4)-> 5 * (4 * (3 * (2 * (1 * fact(0)))))
      //it starts with n as the original value 
      //(5 in this case) and then decrements it by 1 until it reaches the base
      //case of n == 0
}

int main() {
   unsigned int number = 5;
   unsigned int result = factorial(number);
   printf("The factorial of %u is %u\n", number, result);
   return 0;
}

Embed on website

To embed this program on your website, copy the following code and paste it into your website's HTML: