+ 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
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.
+ 7
This version is more like your original:
https://code.sololearn.com/cJ760t1njV6R
+ 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