<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>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                # C++ 程序:查找三個數字中最大的數字 > 原文: [https://www.programiz.com/cpp-programming/examples/largest-number-among-three](https://www.programiz.com/cpp-programming/examples/largest-number-among-three) #### 在此示例中,您將學習使用`if`,`if else`和嵌套的`if else`語句在三個數字中找到最大的數字。 要理解此示例,您應該了解以下 [C++ 編程](/cpp-programming "C++ tutorial")主題: * [C++ `if`,`if...else`和嵌套`if...else`](/cpp-programming/if-else) * * * 在此程序中,要求用戶輸入三個數字。 然后,該程序在用戶輸入的三個數字中找出最大的數字,并顯示適當的消息。 該程序可以以多種方式使用。 * * * ## 示例 1:使用`if`語句查找最大數 ```cpp #include <iostream> using namespace std; int main() { float n1, n2, n3; cout << "Enter three numbers: "; cin >> n1 >> n2 >> n3; if(n1 >= n2 && n1 >= n3) { cout << "Largest number: " << n1; } if(n2 >= n1 && n2 >= n3) { cout << "Largest number: " << n2; } if(n3 >= n1 && n3 >= n2) { cout << "Largest number: " << n3; } return 0; } ``` **輸出** ```cpp Enter three numbers: 2.3 8.3 -4.2 Largest number: 8.3 ``` * * * ## 示例 2:使用`if...else`語句查找最大數 ```cpp #include <iostream> using namespace std; int main() { float n1, n2, n3; cout << "Enter three numbers: "; cin >> n1 >> n2 >> n3; if((n1 >= n2) && (n1 >= n3)) cout << "Largest number: " << n1; else if ((n2 >= n1) && (n2 >= n3)) cout << "Largest number: " << n2; else cout << "Largest number: " << n3; return 0; } ``` **輸出** ```cpp Enter three numbers: 2.3 8.3 -4.2 Largest number: 8.3 ``` * * * ## 示例 3:使用嵌套`if...else`語句查找最大數 ```cpp #include <iostream> using namespace std; int main() { float n1, n2, n3; cout << "Enter three numbers: "; cin >> n1 >> n2 >> n3; if (n1 >= n2) { if (n1 >= n3) cout << "Largest number: " << n1; else cout << "Largest number: " << n3; } else { if (n2 >= n3) cout << "Largest number: " << n2; else cout << "Largest number: " << n3; } return 0; } ``` **輸出** ```cpp Enter three numbers: 2.3 8.3 -4.2 Largest number: 8.3 ```
                  <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>

                              哎呀哎呀视频在线观看