Advertisement
Guest User

Untitled

a guest
Nov 26th, 2015
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.33 KB | None | 0 0
  1. public static int fib(int n) {
  2.      if (n < 2) {
  3.           return n;
  4.      } else {
  5.       return fib(n-1)+fib(n-2);
  6.      }
  7. }
  8.  
  9. double fibbonaci(int n){
  10.    double prev=0, next=1, result=0;
  11.         for (int i = 1; i <n; i++) {
  12.             result=prev+next;
  13.             prev=next;
  14.             next=result;
  15.     }
  16. return result;
  17. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement