<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 程序:使用`switch...case`制作一個簡單的計算器 > 原文: [https://www.programiz.com/c-programming/examples/calculator-switch-case](https://www.programiz.com/c-programming/examples/calculator-switch-case) #### 在此示例中,您將學習使用`switch`語句在 C 編程中創建一個簡單的計算器。 要理解此示例,您應該了解以下 [C 編程](/c-programming "C tutorial")主題: * [C `switch`語句](/c-programming/c-switch-case-statement) * [C `break`和`continue`](/c-programming/c-break-continue-statement) * * * 該程序使用算術運算符`+, -, *, /`和來自用戶的兩個操作數。 然后,它根據用戶輸入的運算符對兩個操作數執行計算。 * * * ## 使用`switch`語句的簡單計算器 ```c #include <stdio.h> int main() { char operator; double first, second; printf("Enter an operator (+, -, *,): "); scanf("%c", &operator); printf("Enter two operands: "); scanf("%lf %lf", &first, &second); switch (operator) { case '+': printf("%.1lf + %.1lf = %.1lf", first, second, first + second); break; case '-': printf("%.1lf - %.1lf = %.1lf", first, second, first - second); break; case '*': printf("%.1lf * %.1lf = %.1lf", first, second, first * second); break; case '/': printf("%.1lf / %.1lf = %.1lf", first, second, first / second); break; // operator doesn't match any case constant default: printf("Error! operator is not correct"); } return 0; } ``` **輸出** ```c Enter an operator (+, -, *,): * Enter two operands: 1.5 4.5 1.5 * 4.5 = 6.8 ``` 用戶輸入的`*`操作符存儲在`operator`中。 并且,將兩個操作數`1.5`和`4.5`分別存儲在`first`和`second`中。 由于運算符`*`與`case '*':`相匹配,因此程序控制跳至 ```c printf("%.1lf * %.1lf = %.1lf", first, second, first * second); ``` 該語句計算產品并將其顯示在屏幕上。 最后,`break;`語句結束`switch`語句。
                  <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>

                              哎呀哎呀视频在线观看