Implementation of recursive problems using C++