Given the following: int fun(int x) { if(x<1) return1; else returnx + fun(x - 1)
ID: 3608576 • Letter: G
Question
Given the following: int fun(int x) { if(x<1) return1; else returnx + fun(x - 1) + fun(x - 2); } a)What is returned by callfun(4) ? b)What is returned by callfun(5) ? c)Whatis returned by call fun(2)? d)What is returned by callfun(6) ? Given the following: int fun(int x) { if(x<1) return1; else returnx + fun(x - 1) + fun(x - 2); } } a)What is returned by callfun(4) ? b)What is returned by callfun(5) ? c)Whatis returned by call fun(2)? d)What is returned by callfun(6) ? c)Whatis returned by call fun(2)? d)What is returned by callfun(6) ? d)What is returned by callfun(6) ?Explanation / Answer
a) func(4)=4+func(3)+func(2) func(3)=3+func(2)+func(1) func(2) = 2+func(1)+func(0) func(0) = 1 func(1) = 1+1+1=3 func(2)=2+3+1=6 func(3)=3+6+3=12 func(4)=4+func(3)+func(2) = 4+12+6=22 b) func(5)=5+func(4)+func(3)=5+22+12=39 c) as we calculate in (a), func(2)=6 d) func(6) = 6+func(5)+func(4)=6+39+22=67Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.