In your function L(int x)
If x
is 0 or 1
return 1;
If x
is greater than 1
return L(x-1) + L(x-2) + 1;
What I am doing using L(x - 1)
is calling the function for the value x - 1
and the value will be evaluated directly as 1 if it is 0 or 1, otherwise it call again for (x - 1) - 1
i.e. x - 2
and the process repeats.
Same is the case for calling L(x - 2)
.
This is the logic, without the entire code.
For more information on this kind of logic, try searching for Recursion.
1
solved What is the logic to find out Leonardo number in C programming? [closed]