Article

Chapter-12(Recursion-in-Detail)


Recursion:-

The method of calling a function into itself is known as recursion. It increases the execution speed of a compiler but occupies a lot of memory.

Example:-

int factorial (int n)

{

if(n==0)

{

return 1;

}

else

{

return n*factorial(n-1);

}

}

void main()

{

int n,r;

printf("enter any no.");

scanf("%d",&n);

r=factorial(n);

printf("%d",r);

}


Result:-

5!=5*4*3*2*1

    =5*4!

formula of factorial:

n!=n*(n-1)!