Good old fibonacci and this post will be updated later on but bear with this Java one:
public class FibonacciExt {
public static void main(String[] args) {
// System.out.println(fibonacci(10, 4));
for (int j = 1; j < 15; j++) System.out.print(" " + fibonacci(j, 3));
System.out.println("");
}
public static int fibonacci(int n, int k) {
int sum = 0;
if (n == 1)
return 1;
else if (n == 2) return 1;
else if (n == 3) return 2;
else {
sum = 0;
for (int j = 1; j <= k; j++)
sum += fibonacci(n - j, k);
}
return sum;
}
}
and the output is as follows:
1 1 2 4 7 13 24 44 81 149 274 504 927 1705