0
how can i learn recursion for patterns.
recursion for patterns.
3 Respostas
+ 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
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);
}
0
by patterns i meant pyramids and triangled