ex0405.cpp

来自「practice c++, it is from the book http:/」· C++ 代码 · 共 24 行

CPP
24
字号
//  Programming with C++, Second Edition, by John R. Hubbard
//  Copyright McGraw-Hill, 2000
//  Example 4.5 on page 62
//  The Fibonacci numbers

#include <iostream>
using namespace std;

int main()
{ // prints Fibonacci numbers:
  long bound;
  cout << "Enter a positive integer: ";
  cin >> bound;
  cout << "Fibonacci numbers < " << bound << ":\n0, 1";
  long f0=0, f1=1;
  while (true)
  { long f2 = f0 + f1;
    if (f2 > bound) break;  // terminates the loop immediately
    cout << ", " << f2;
    f0 = f1;
    f1 = f2;
  }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?