0

Recursion

How to get this answer? int go(int x) { if (x<1) return x; else return x + go(x-1); } What is go(6)? //answer 6

10th Mar 2023, 6:05 PM
Sara
Sara - avatar
2 Respostas
+ 4
recursive functions can be treated similar to loops in above case the function is repeatedly calling itself till the value of i is >=1 therefore the function is called i times, so, we can simply explain it as: 6+go(6-1) 6+5+go(5-1) ... 6+5+4+3+2+1 = 21
10th Mar 2023, 6:11 PM
Just Some Random Guy
Just Some Random Guy - avatar
0
Sara Yamaguchi Please attach the code with programming language tag
10th Mar 2023, 6:07 PM
Sakshi [Offline 🙃]
Sakshi [Offline 🙃] - avatar