Advertisement
ranisalt

C++ Fibonacci

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