<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語言的唯一的三目運算符,即它需要3個數據或表達式構成條件表達式 - 格式: + 表達式1?表達式2(結果A):表達式3(結果B) - 求值規則: + 如果表達式1為真,三目運算符的運算結果為表達式2的值(結果A),否則為表達式3的值(結果B) 示例: ``` int a = 10; int b = 20; int max = (a > b) ? a : b; printf("max = %d", max); // 輸出結果: 20 ``` 等價于: ``` int a = 10; int b = 20; int max = 0; if(a>b){ max=a; }else { max=b; } printf("max = %d", max); ``` ## 注意點 - 條件運算符的運算優先級低于關系運算符和算術運算符,但高于賦值符。 ``` 例如: max=(a>b)? a:b; 可以去掉括號而寫為: max=a>b?a:b; ``` - 條件運算符?和:是一對運算符,不能分開單獨使用。 - 條件運算符的結合方向是從右至左 例如: ``` a>b?a:c>d?c:d; // 應理解為: a>b?a:(c>d?c:d) ``` ## 練習 問:用戶從鍵盤上輸入三個整數,找出最大值嗎,然后輸入最大值。 思路: 1. 定義變量 num1,num2,num3,max 2. 先比較 num1 和 num2,比較的結果存放到max 3. max和第三個數比較 ``` #include<stdio.h> int main(){ int num1, num2, num3; printf("請輸入三個整型,使用逗號分割,并以回車結束輸入\n"); scanf("%i,%i,%i",&num1, &num2, &num3); int temp = num1 > num2 ? num1 : num2; int resault = temp > num3 ? temp : num3; printf("你輸入的最大整型是:%i\n\n" , resault); return 0; } ```
                  <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>

                              哎呀哎呀视频在线观看