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

                ??碼云GVP開源項目 12k star Uniapp+ElementUI 功能強大 支持多語言、二開方便! 廣告
                遞歸函數,也就是不斷的調用自身的函數,使用遞歸能夠比較方便的解決一些比較難使用循環解決的問題。就在這個例子中,求一個數組a[]的前n項和,也就是求a[n-1]+a[n-2]+…+a[0],那么如果一個函數sum是用來求數組前n項和的,sum定義為sum(int a[],int n),則使用遞歸的方式就是 a[n-1]+sum(a,n-1)。 使用代碼來表述可能更好一些: ~~~ #include <stdio.h> int sum(int test[],int n); /** * @brief main 使用遞歸求一個數組的前n個元素的和 * 假設數組為a[];則求其前n的元素的和也就是求 * a[n-1]+a[n-2]+...a[0] * @return */ int main(void) { int n; printf("Please input the number of an array:\n"); scanf("%d",&n); printf("Please enter the element of the array:\n"); int test[n]; int i; for(i = 0;i < n;i++) scanf("%d",&test[i]); int count = sum(test,n); printf("The sum of the array is : %d.\n",count); return 0; } /** * @brief sum 實現前n個元素的和 * @param test 要求和的數組 * @param n 所要求的前n個元素 * @return 返回前n個元素的和 */ int sum(int test[],int n){ if(n <= 0) return 0; return test[n-1]+sum(test,n-1); } ~~~ 下面是我的程序的輸出,這個程序比較簡單。 ![這里寫圖片描述](https://box.kancloud.cn/2016-05-24_5743c0752130f.jpg "")
                  <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>

                              哎呀哎呀视频在线观看