<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                # C++ 程序:顯示斐波那契數列 > 原文: [https://www.programiz.com/cpp-programming/examples/fibonacci-series](https://www.programiz.com/cpp-programming/examples/fibonacci-series) #### 在本文中,您將學習在 C++ 編程中打印斐波那契序列(最多 n 項,最多特定數目)。 要理解此示例,您應該了解以下 [C++ 編程](/cpp-programming "C++ tutorial")主題: * [C++ `for`循環](/cpp-programming/for-loop) * [C++ `while`和`do...while`循環](/cpp-programming/do-while-loop) * * * 斐波那契數列是一個系列,其中下一項是前兩個項的總和。 斐波那契數列的前兩個項是 0,然后是 1。 ```cpp The Fibonacci sequence: 0, 1, 1, 2, 3, 5, 8, 13, 21 ``` * * * ## 示例 1:斐波那契數列,最多 n 個項 ```cpp #include <iostream> using namespace std; int main() { int n, t1 = 0, t2 = 1, nextTerm = 0; cout << "Enter the number of terms: "; cin >> n; cout << "Fibonacci Series: "; for (int i = 1; i <= n; ++i) { // Prints the first two terms. if(i == 1) { cout << " " << t1; continue; } if(i == 2) { cout << t2 << " "; continue; } nextTerm = t1 + t2; t1 = t2; t2 = nextTerm; cout << nextTerm << " "; } return 0; } ``` **輸出** ```cpp Enter the number of terms: 10 Fibonacci Series: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, ``` * * * ## 示例 2:生成一定數目的斐波那契數列的程序 ```cpp #include <iostream> using namespace std; int main() { int t1 = 0, t2 = 1, nextTerm = 0, n; cout << "Enter a positive number: "; cin >> n; // displays the first two terms which is always 0 and 1 cout << "Fibonacci Series: " << t1 << ", " << t2 << ", "; nextTerm = t1 + t2; while(nextTerm <= n) { cout << nextTerm << ", "; t1 = t2; t2 = nextTerm; nextTerm = t1 + t2; } return 0; } ``` **輸出** ```cpp Enter a positive integer: 100 Fibonacci Series: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ```
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看