recursive functionsrecursion is a process by


Recursive Functions

Recursion is a process by which a function includes itself with a condition for its safe exit. It is best suitable for a recursive problem. A typical example is the factorial problem, the programs without and with recursive functions are shown below.

void main()

 {

   long factorial ( int num); // Forward declaration of

       //a function

   int num;

printf("\n Enter a number:");

scanf("5d",&num);

printf(" Factorial of 5d is %ld",num,factorial(num));

  }

long factorial(int num)   // Non recursive

 {

   long f=1;

while ( n)

                 {

                   f = f * n;

                   n--;

                 }

                return(f);

 }

long factorial(int num)   // Recursive

 {

                if(n == 1)

                                return (1);

                else

                                return( n* factorial(n-1));

 }

 

Request for Solution File

Ask an Expert for Answer!!
C/C++ Programming: recursive functionsrecursion is a process by
Reference No:- TGS0309213

Expected delivery within 24 Hours