Recursive Function

Pallab Sarkar
Nov 8, 2020

All modern programming languages can solve many complex problems using this Recursive Function. Although not understood correctly, because many of them do not use this method. Recursive Function means a function when it calls itself inside itself. This process continues until the Function returns a number for a specific parameter. Let’s look at the matter clearly with an example.

int factorial ( int i ) //line 1
{ //line 2
if ( i == 0) //line 3
return 1; //line 4
return i * factorial ( i — 1); //line 5
}
//line 6

Here the factorial (i) function calls factorial (i-1) to calculate its own value. Since T calls itself a different parameter inside itself, it is a recursive function. Suppose we are calling factorial (4). In this case, it will call factorial (3). Which will again call factorial (2). This process will continue until factorial (0) is called, which will return 1. Which will then be used to calculate factorial (1) in the reverse process. This process will continue until a specific value for factorial (4) is reached.
factorial (0) = 1, factorial (1) = 1 * 1, factorial (2) = 2 * 1 * 1, factorial (3) = 3 * 2 * 1 * 1, factorial (4) = 4 * 3 * 2 * 1 * 1 = 24

In this process, more complex problems like the Fibonacci series, the Tower of Hanoi, can be easily solved using a few line programs.

--

--