0

#include<iostream> using namespace std; void f(int n) { if (n == 1 || n == 0) return; else { cout <

Anyone can please explain this? How the output is 14 times Hello? How many times f(n-1) execute & f(n-2)? Explain step by step please!

2nd Jun 2019, 7:41 AM
Shehroz Irfan
Shehroz Irfan - avatar
5 Réponses
+ 5
Inside the function you print 2 times hello. So each call of f(n) produces 2 hello's. I think it is like that: r = return (when n = 1) f(5) / \ f(4) f(3) / \ / \ f(3) f(2) f(2) r / \ f(2) r 7 calls of f(n) -> 14 prints of hello
2nd Jun 2019, 10:43 AM
Denise Roßberg
Denise Roßberg - avatar
+ 5
Please upload your code to the code playground and post a link here https://www.sololearn.com/Discuss/1316935/welcome-to-sololearn-forum/
2nd Jun 2019, 7:50 AM
Anna
Anna - avatar
+ 3
Denise Roßberg Thank you 💚👍
2nd Jun 2019, 11:24 AM
Shehroz Irfan
Shehroz Irfan - avatar
2nd Jun 2019, 7:52 AM
Shehroz Irfan
Shehroz Irfan - avatar
+ 2
Anna Link posted
2nd Jun 2019, 7:55 AM
Shehroz Irfan
Shehroz Irfan - avatar