Discussion Forums

New User? Please read instructions!

What is recursive function and provide C program for recursive function  

  RSS

thiyagarajan
Eminent Member
Joined:10 months  ago
Posts: 26
27/01/2017 9:44 am  

What is recursive function and provide C program for recursive function


ReplyQuote
admin
Eminent Member Admin
Joined:5 years  ago
Posts: 26
01/02/2017 6:52 am  

What is recursive function?

When a function in C program calls by itself, then that function is called recursive function. This process is called recursion.

 

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.

 

#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


ReplyQuote
  
Working

Please Login or Register






Share this website !!!
Facebook Twitter Linkedin