Calculate factorials using recursion : Recursive Function « Function « C Tutorial






#include <stdio.h>

unsigned long factorial(unsigned long);

int main(void)
{
  unsigned long number = 0L;
  printf("\nEnter an integer value: ");
  scanf(" %lu", &number);
  printf("\nThe factorial of %lu is %lu\n", number, factorial(number));
  return 0;
}

unsigned long factorial(unsigned long n)
{
  if(n < 2L)
    return n;
  else
    return n*factorial(n - 1L);
}








8.8.Recursive Function
8.8.1.Recursion
8.8.2.Calculate factorials using recursion
8.8.3.Recursive fibonacci function