0

how can i learn recursion for patterns.

recursion for patterns.

14th Feb 2017, 12:17 AM
Faiq Iftikhar
3 ответов
+ 1
For learning recursion, it is good to think about your algorithm and what the smallest unit of work is that it will be doing, and when you want it to stop recursing deeper. If you write your unit of work so that it will return a value depending on the input, then you can arrange multiple units of work with return statements for each within the function, and just call the function again at the bottom of your function block. M
14th Feb 2017, 12:27 AM
Daniel W.
Daniel W. - avatar
0
You can create a Fibonacci method that create a sequence of numbers with recursion like this: int fib(int n) { if (n <= 0) return 0; else if (n == 1) return 1; else return fib(n − 1) + fib(n − 2); }
14th Feb 2017, 12:29 AM
David Oats
David Oats - avatar
0
by patterns i meant pyramids and triangled
14th Feb 2017, 12:31 AM
Faiq Iftikhar