Q:

C PROGRAM FOR RECURSIVE FUNCTION:

0

C PROGRAM FOR RECURSIVE FUNCTION:

Factorial and Fibonacci series will be a good example for recursive function as it calls by itself. Let’s discuss about Factorial program here.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

#include <stdio.h>
 
int factorial(unsigned int);
 
 
 
int  main()
 
{
 
    int i = 8;
 
    printf("Factorial of the number %d is %d\n", i, factorial(i));
 
    return 0;
 
}
 
 
 
int factorial(unsigned int i)
 
{
 
   if(i < 2) 
 
   {
 
      return 1;
 
   }
 
   return i * factorial(i - 1);
 
}

Output:

Factorial of the number 8 is 40320

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now