Solution to some well known programming questions.
Sunday, October 7, 2012
write a function fib(n,k) which gives you first n numbers of a Fibonacci series and k is the number of previous numbers you have to add.
public int fibonacci(int n, int k) { if (n <= 0) return 0; if (n==1) return 1; int result =0 ; for (int i = 1; i <= k; i++) { result += fibonacci(n-i, k); } return result; }
No comments:
Post a Comment