Wednesday, December 2, 2015
Finding nth Fibonacci number
public int getFibonacci(int n) {
if(n<=1) return 1;
int fibonace=0;
int f1=0;
int f2=1;
for(int i=1; i<n; i++) {
fibonace=f1+f2;
f1=f2;
f2=fibonace;
}
return fibonace;
}
No comments:
Post a Comment
Newer Post
Older Post
Home
Subscribe to:
Post Comments (Atom)
UA-39217154-2
No comments:
Post a Comment