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

                企業??AI智能體構建引擎,智能編排和調試,一鍵部署,支持知識庫和私有化部署方案 廣告
                # C 程序:使用用戶定義的函數檢查質數或阿姆斯特朗數 > 原文: [https://www.programiz.com/c-programming/examples/prime-armstrong-function](https://www.programiz.com/c-programming/examples/prime-armstrong-function) #### 在此示例中,您將學習通過創建兩個單獨的函數來檢查整數是質數還是阿姆斯特朗數還是兩者都是。 要理解此示例,您應該了解以下 [C 編程](/c-programming "C tutorial")主題: * [C `for`循環](/c-programming/c-for-loop) * [C `while`和`do...while`循環](/c-programming/c-do-while-loops) * [C `break`和`continue`](/c-programming/c-break-continue-statement) * [C 函數](/c-programming/c-functions) * [C 編程中用戶定義函數的類型](/c-programming/types-user-defined-functions) * * * 在該程序中,創建了兩個用戶定義的函數`checkPrimeNumber()`和`checkArmstrongNumber()`。 如果用戶輸入的數字是質數,則`checkPrimeNumber()`函數將返回`1`。 同樣,如果用戶輸入的號碼是阿姆斯特朗數,則`checkArmstrongNumber()`函數也會返回`1`。 訪問這些頁面以了解檢查數字是否為 * [是否為質數](https://www.programiz.com/c-programming/examples/prime-number) * [是否為阿姆斯特朗數](https://www.programiz.com/c-programming/examples/check-armstrong-number) * * * ## 示例:檢查質數和阿姆斯特朗數 ```c #include <math.h> #include <stdio.h> int checkPrimeNumber(int n); int checkArmstrongNumber(int n); int main() { int n, flag; printf("Enter a positive integer: "); scanf("%d", &n); // check prime number flag = checkPrimeNumber(n); if (flag == 1) printf("%d is a prime number.\n", n); else printf("%d is not a prime number.\n", n); // check Armstrong number flag = checkArmstrongNumber(n); if (flag == 1) printf("%d is an Armstrong number.", n); else printf("%d is not an Armstrong number.", n); return 0; } // function to check prime number int checkPrimeNumber(int n) { int i, flag = 1, squareRoot; // computing the square root squareRoot = sqrt(n); for (i = 2; i <= squareRoot; ++i) { // condition for non-prime number if (n % i == 0) { flag = 0; break; } } return flag; } // function to check Armstrong number int checkArmstrongNumber(int num) { int originalNum, remainder, n = 0, flag; double result = 0.0; // 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); } // condition for Armstrong number if (round(result) == num) flag = 1; else flag = 0; return flag; } ``` **輸出** ```c Enter a positive integer: 407 407 is not a prime number. 407 is an Armstrong number. ```
                  <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>

                              哎呀哎呀视频在线观看