Trace the execution of the following program by understanding the recursive functions.…
- User
Trace the execution of the following program by understanding the recursive functions. Show what it will printed to the screen if user enters "wxyz" to the cin prompt, no explaination needed just shows output
#include using namespace std;
int f1(int x){ if(x >= 0) { return x; } else return f1(-x); }
int f2(int k){ if(k == 0){ return 0; } else { return 1 + f2(k/2); } }
int main() { cout << f1(-3) << endl; cout << f2(8) << endl; cout << f2(100) << endl; return 0; }
- Assistantcode
3 4 7 - User
Trace the execution of the following program by understanding the recursive functions. Show what it will printed to the screen if user enters “wxyz” to the cin prompt, no explaination needed just shows output
#include #include using namespace std; string f1(string sa, string sb) { if(sa.size() < 2) { cout << "B " << sb << endl; return sb; } else { string sc = f1(sa.substr(2), sb + "*"); cout << "A " << sc << endl; sc += sa[0]; return sc; } } int main() { string s, instr; cin >> instr; s = f1(instr, ""); cout << s << endl; return 0; }
- Assistantcode
B x* A x*w A x*w* A x*w*z x*w*z*y