luckily i can answer almost all question, but not the Fibonacci question.
the question ask to write a recursive function that will return the 'n' Fibonacci number.
this question is far more easy then what i aspect, i am the one who make the question difficult only...
the answer just a few line code, but mine one more then the answer should be...
//my answerhopefully next time i will not make this kind of mistake
int fib(int n,int fib1,int fib2){
if(n>0){
int temp=fib2+fib1;
fib1=fib2;
fib2=temp;
return fib(n-1,fib1,fib2);
}
else
return fib2;
}
//the answer below
int fib(int n){
if(n==0||n==1)
return 1;
else
return fib(n-1)+fib(n-2);
}
0 Response to 'today test..'