<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/c-programming/examples/swapping](https://www.programiz.com/c-programming/examples/swapping) #### 在此示例中,您將學習使用兩種不同的技術在 C 編程中交換兩個數字。 要理解此示例,您應該了解以下 [C 編程](/c-programming "C tutorial")主題: * [C 數據類型](/c-programming/c-data-types) * [C 編程運算符](/c-programming/c-operators) * [C 輸入輸出(I/O)](/c-programming/c-input-output) * * * ## 使用臨時變量交換數字 ```c #include<stdio.h> int main() { double first, second, temp; printf("Enter first number: "); scanf("%lf", &first); printf("Enter second number: "); scanf("%lf", &second); // Value of first is assigned to temp temp = first; // Value of second is assigned to first first = second; // Value of temp (initial value of first) is assigned to second second = temp; printf("\nAfter swapping, firstNumber = %.2lf\n", first); printf("After swapping, secondNumber = %.2lf", second); return 0; } ``` **輸出** ```c Enter first number: 1.20 Enter second number: 2.45 After swapping, firstNumber = 2.45 After swapping, secondNumber = 1.20 ``` 在上述程序中,為`temp`變量分配了`first`變量的值。 然后,將`second`變量的值分配給`first`變量。 最后,將`temp`(其保存`first`)分配給`second`。 這樣就完成了交換過程。 * * * ## 交換數字而不使用臨時變量 ```c #include <stdio.h> int main() { double a, b; printf("Enter a: "); scanf("%lf", &a); printf("Enter b: "); scanf("%lf", &b); // Swapping ? // a = (initial_a - initial_b) a = a - b; ? // b = (initial_a - initial_b) + initial_b = initial_a b = a + b; ? // a = initial_a - (initial_a - initial_b) = initial_b a = b - a; printf("After swapping, a = %.2lf\n", a); printf("After swapping, b = %.2lf", b); return 0; } ``` **輸出** ```c Enter a: 10.25 Enter b: -12.5 After swapping, a = -12.50 After swapping, b = 10.25 ```
                  <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>

                              哎呀哎呀视频在线观看