manasij7479

Fib

May 30th, 2012
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.20 KB | None | 0 0
  1. unsigned long find_fib_n(int n)
  2. {
  3.     unsigned long pre[2]={1,1};
  4.     if(n==1||n==2)return 1;
  5.     for(int i=0;i<n-2;i++)
  6.     {
  7.         int x = pre[0]+pre[1];
  8.         pre[0]=pre[1];
  9.         pre[1]=x;
  10.     }
  11.     return pre[1];
  12. }
Advertisement
Add Comment
Please, Sign In to add comment