#include <stdio.h>
int sumAryB(int a[], int s, int e) {
int m,sum1,sum2;
if(s==e)
return a[s];
m=(s+e)/2;
sum1=sumAryB(a,s,m);
sum2=sumAryB(a,m+1,e);
return sum1+sum2;
}
int main(void) {
int x[] = { 3, 1, 4, 1, 5, 9, 2, 6, 5, 3 }; /* 合計は 39 */
printf("配列の値の合計:%d\n", sumAryB
(x
, 0, 9)); return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CgppbnQgc3VtQXJ5QihpbnQgYVtdLCBpbnQgcywgaW50IGUpIHsKICAgIGludCBtLHN1bTEsc3VtMjsKICAgIGlmKHM9PWUpCiAgICByZXR1cm4gYVtzXTsKICAgIG09KHMrZSkvMjsKICAgIHN1bTE9c3VtQXJ5QihhLHMsbSk7CiAgICBzdW0yPXN1bUFyeUIoYSxtKzEsZSk7CiAgICByZXR1cm4gc3VtMStzdW0yOwp9CgppbnQgbWFpbih2b2lkKSB7CiAgICBpbnQgeFtdID0geyAzLCAxLCA0LCAxLCA1LCA5LCAyLCA2LCA1LCAzIH07IC8qIOWQiOioiOOBryAzOSAqLwoKICAgIHByaW50Zigi6YWN5YiX44Gu5YCk44Gu5ZCI6KiI77yaJWRcbiIsIHN1bUFyeUIoeCwgMCwgOSkpOwogICAgcmV0dXJuIDA7Cn0K