The exam question below attempts to test a student's understanding of recursion in c++,…
- User
The exam question below attempts to test a student's understanding of recursion in c++, i want you to create 3 more problems of similar kinds but slighty more complex and diffiicult to more accurately test one's understanding of recursion. Particularly, use problems that includes theme that's commonly used in university exams, characterized by its confusing and distinct nature
Trace the execution of the following program by understanding the recursive functions. Show what it will printed to the screen.
(Do not show the endl or \n explicitly in your answer).
#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; }
- Assistant
Certainly! Below are three problems that delve deeper into recursion, designed to assess and improve a student's understanding, particularly focusing on themes that create intricacies and conceptual challenges often encountered in university-level exams.