Advertisement
Guest User

Untitled

a guest
Oct 6th, 2015
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.39 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. long int fibo(long int n){
  6.     long int t1=1,t2=1,temp;
  7.     if(n==1)
  8.         return 1;
  9.     if(n==2)
  10.         return 1;
  11.     else if(n>=2)
  12.      for(long int i=1;i<n-2;i++) {
  13.         temp=t1+t2;
  14.         t1=t2;
  15.         t2=temp;
  16.     }
  17.        return temp;
  18. }
  19.  
  20. int main()
  21. {
  22.     long int p;
  23.     cin>>p;
  24.     cout<<fibo(p)<<endl;
  25.     return 0;
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement