check ab using recursion in c++