Advertisement
fueanta

Conditional Fibonacci

Sep 6th, 2016
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.39 KB | None | 0 0
  1. /* A program to print out items in the series 1 1 2 3 5 8 13 ... until the last term is greater than 10000
  2.  * Author : Taqui
  3.  */
  4.  
  5. #include <iostream>
  6.  
  7. using namespace std;
  8.  
  9. int main() {
  10.     int i=1,j=1; cout << i << " ";
  11.     for (int k=1;k<=10000;k=i+j) {
  12.         cout << k << " ";
  13.         i=j;
  14.         j=k;
  15.         if (i+j>10000)
  16.             cout << i+j;
  17.     }
  18.     return 0;
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement