+ 4

Can somebody explain the recursive functions with details?

I red it's definition but didn't understand

10th Nov 2018, 8:56 AM
Otabek Karimov
Otabek Karimov - avatar
10 Answers
+ 3
look recursive function is a function, which calls himself until the condition is true. For example: int name(int num) { if (num == 1) return 1; return num+name(num-1); } if we pass lets say 3 to it, it will return 3+2+1
10th Nov 2018, 9:25 AM
Sokrat_Poghosyan
Sokrat_Poghosyan - avatar
+ 3
Hey brother check this.you can understand how recursion works. https://www.sololearn.com/discuss/1149517/?ref=app
11th Nov 2018, 9:01 AM
Maninder $ingh
Maninder $ingh - avatar
+ 2
Great question Otabek Karimov
11th Nov 2018, 2:39 AM
Saul
Saul  - avatar
+ 1
Recursion is where a method calls itself. this is useful where you may want to loop recursively vs looping iteratively (like standard for loop) int factorial(int num) { if(num == 1) return 1; return factorial(num - 1) * num; } This example recursively finds the factorial of "num"
10th Nov 2018, 9:31 AM
John
John - avatar
+ 1
yea I see that now
10th Nov 2018, 9:39 AM
John
John - avatar
+ 1
Thank you for explaining
10th Nov 2018, 9:46 AM
Otabek Karimov
Otabek Karimov - avatar
+ 1
Recursive function simply known as repeated function. It's used for repeated function execution in program. Example factorial numbe. It's calls the function when condition is true another way return the value.
11th Nov 2018, 11:35 AM
S.Vijayarasan Shivanandham
0
That's funny that we had the same idea, I didn't see the post until after I posted mine haha
10th Nov 2018, 9:35 AM
John
John - avatar
0
John yea ) the most common case to learn is factorial, I’ve tried to explain a bit easier )
10th Nov 2018, 9:36 AM
Sokrat_Poghosyan
Sokrat_Poghosyan - avatar
0
my example is not computing factorial ))
10th Nov 2018, 9:38 AM
Sokrat_Poghosyan
Sokrat_Poghosyan - avatar