<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智能體構建引擎,智能編排和調試,一鍵部署,支持知識庫和私有化部署方案 廣告
                # Kotlin 程序:使用遞歸查找 GCD > 原文: [https://www.programiz.com/kotlin-programming/examples/gcd-hcf-recursion](https://www.programiz.com/kotlin-programming/examples/gcd-hcf-recursion) #### 在此程序中,您將學習使用 Kotlin 中的遞歸函數查找 GCD(最大公約數)或 HCF。 該程序采用兩個正整數,并使用遞歸計算 <abbr title="Greatest Common Divisor">GCD</abbr> 。 訪問此頁面以了解如何使用循環來[計算 GCD](/kotlin-programming/examples/hcf-gcd "GCD using loops in Kotlin")。 ## 示例:使用遞歸的兩個數字的 GCD ```kt fun main(args: Array<String>) { val n1 = 366 val n2 = 60 val hcf = hcf(n1, n2) println("GCD of $n1 and $n2 is $hcf.") } fun hcf(n1: Int, n2: Int): Int { if (n2 != 0) return hcf(n2, n1 % n2) else return n1 } ``` 運行該程序時,輸出為: ```kt GCD of 366 and 60 is 6. ``` 在上面的程序中,遞歸函數被調用直到`n2`為 0。最后,`n1`的值是給定兩個數字的 GCD 或 HCF。 執行步驟 | 序號 | 遞歸調用 | `n1` | `n2` | `n1 % n2` | | --- | --- | --- | --- | --- | | 1 | `hcf(366, 60)` | 366 | 60 | 6 | | 2 | `hcf(60, 6)` | 60 | 6 | 0 | | 最后 | `hcf(6, 0)` | 6 | 0 | - | 這是等效的 Java 代碼:[使用遞歸查找 GCD 的 Java 程序](/java-programming/examples/gcd-hcf-recursion "Java Program to Find GCD using recursive function")。
                  <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>

                              哎呀哎呀视频在线观看