Compute the Factorial of a Number Using Recursion - C Function

C examples for Function:Recursive Function

Description

Compute the Factorial of a Number Using Recursion

Demo Code

#include <stdio.h>

unsigned long int fact(int i);

int main()/*from w  w  w .j  a v  a2  s. c o m*/
{
   int counter =  10;
   unsigned long int number;

   number = fact(counter);

   printf("%d! = %ld\n", counter, number);

   return(0);
 }

unsigned long int fact(int i)
{
  if (i == 1)
    return 1;
  else
    return (i * fact(i - 1));
}

Related Tutorials