Guest User

fib

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