<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/check-armstrong-number](https://www.programiz.com/c-programming/examples/check-armstrong-number) #### 在此示例中,您將學習檢查用戶輸入的整數是否是阿姆斯特朗數。 要理解此示例,您應該了解以下 [C 編程](/c-programming "C tutorial")主題: * [C `if...else`語句](/c-programming/c-if-else-statement) * [C `while`和`do...while`循環](/c-programming/c-do-while-loops) * * * 如果一個正整數稱為阿姆斯特朗數(階數`n`),則 ```c abcd... = a<sup>n</sup> + b<sup>n</sup> + c<sup>n</sup> + d<sup>n</sup> + ``` 對于 3 位的阿姆斯特朗數,每個數字的立方數之和等于數字本身。 例如,153 是阿姆斯特朗數,因為 ```c 153 = 1*1*1 + 5*5*5 + 3*3*3 ``` * * * ## 檢查阿姆斯特朗三位數 ```c #include <stdio.h> int main() { int num, originalNum, remainder, result = 0; printf("Enter a three-digit integer: "); scanf("%d", &num); originalNum = num; while (originalNum != 0) { // remainder contains the last digit remainder = originalNum % 10; result += remainder * remainder * remainder; // removing last digit from the orignal number originalNum /= 10; } if (result == num) printf("%d is an Armstrong number.", num); else printf("%d is not an Armstrong number.", num); return 0; } ``` **輸出** ```c Enter a three-digit integer: 371 371 is an Armstrong number. ``` * * * ## 檢查阿姆斯特朗 n 位數字 ```c #include <math.h> #include <stdio.h> int main() { int num, originalNum, remainder, n = 0; float result = 0.0; printf("Enter an integer: "); scanf("%d", &num); originalNum = num; // store the number of digits of num in n for (originalNum = num; originalNum != 0; ++n) { originalNum /= 10; } for (originalNum = num; originalNum != 0; originalNum /= 10) { remainder = originalNum % 10; // store the sum of the power of individual digits in result result += pow(remainder, n); } // if num is equal to result, the number is an Armstrong number if ((int)result == num) printf("%d is an Armstrong number.", num); else printf("%d is not an Armstrong number.", num); return 0; } ``` **輸出** ```c Enter an integer: 1634 1634 is an Armstrong number. ``` 在該程序中,首先計算一個整數的位數,并將其存儲在`n`中。 并且,`pow()`函數用于計算第二`for`循環的每次迭代中各個數字的冪。
                  <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>

                              哎呀哎呀视频在线观看