+ 1

Any program can be written using recursive function in c++ or not?

https://code.sololearn.com/cFsxf9xm66ga/?ref=app Can this program is possible to write in the format of rescursive function

24th Jan 2019, 6:37 PM
Nitin Madas
Nitin Madas - avatar
3 Respuestas
+ 8
Any loop can be replaced with recursion. Any recursion can be replaced with a loop. However, sometimes the loop is easier to understand and other times the recursion is easier. Unless you are required to use a method, always use the easiest to understand for your code.
24th Jan 2019, 7:30 PM
John Wells
John Wells - avatar
+ 7
This version is more like your original: https://code.sololearn.com/cJ760t1njV6R
24th Jan 2019, 7:25 PM
John Wells
John Wells - avatar
+ 5
Fibonacci serie is a textbook example of something using recursion, so yes. base cases: fib(0) = 0 fib(1) = 1 case of n >=2: fib(n) = fib(n-1)+fib(n-2) https://code.sololearn.com/cWOothBAImcz/?ref=app https://code.sololearn.com/cX1b84CsDDrF/?ref=app
24th Jan 2019, 6:57 PM
Zen
Zen - avatar