I have written a recursive function, but the recursion takes a lot of time when I enter a big number, such as 100.
I want to apply tail call optimization in the code, to minimize the computation time, but I am not able to do it.
The recursive algorithm is f(n) = f(n-1) + f(n-2)
int fib(int n)
{
if (n == 1) return n;
if (n == 0) return n;
return fib(n - 1) + fib(n - 2);
}
int _tmain(int argc, _TCHAR* argv[])
{
std::cout << "---->" << fib(3);
std::system("PAUSE");
return 0;
}