1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
|
int BinarySUM (int Array [], int i, int n)
{
if (n == 1){
return Array [i];
}
else{
return BinarySUM (Array, i, (n/2)) + BinarySUM (Array, i + (n/2), (n/2));
}
}
int main ()
{
const int n = 9;
int Array [n] = {1,2,3,4,5,6,7,8,9};
int Sum = 0;
for (int i = 0; i < n; i++){
cout << Array [i] << " ";
}
for (int i = 0; i < n; i++){
Sum += Array [i];
}
cout << "\n" << Sum;
cout << "\n" << BinarySUM (Array, 0, n);
}
|