Original topic:
Write a recursive program that extends the range of the Fibonacci sequence. The Fibonacci sequence is 1, 1, 2, 3, 5, 8, etc., where each element is the sum of the previous and the elements. For this problem, instead of only adding the last and the last of the nth element, which has the nth Elem ent be the sum of the previous K elements. For example, the 7th Fibonacci element summing the previous 3 elements would is 37. The sequence is 1 1 2 4 7 13. Be sure to check your code by running it with a K value of 2 and comparing the value to the value you would obtai N with the regular Fibonacci sequence (they should be the same)
Probably the meaning is the deformation of the Fibonacci series: that is, a number in the sequence is no longer the first two number of combined with, but the number of former K plus and, but also to be implemented by recursion.
The topic feels more interesting, so excerpt here, casually look.
Private Static intFibintNintk) { intTmp=0; if(n<k) { if(n==1| | n==2) return1; Else if(n<1) return0; for(inti=1;i<=n;i++) {tmp= tmp +FIB (ni,k); } } Else{ for(inti=1;i<=k;i++) {tmp+=FIB (ni,k); } } returntmp; }
Variable-length Fibonacci series