#include <iterator>
#include <iostream>
int sum(int* a, unsigned size, int acc = 0)
{
if ( size == 0 )
return acc ;
else
return sum(a+1, size-1, acc + *a);
}
int main()
{
int array[] = { 1, 2, 3, 4, 5, 6 } ;
unsigned array_size = std::end(array) - std::begin(array) ;
std::cout << sum(array, array_size) << " is the sum of elements in array.\n" ;
}
I2luY2x1ZGUgPGl0ZXJhdG9yPgojaW5jbHVkZSA8aW9zdHJlYW0+CgppbnQgc3VtKGludCogYSwgdW5zaWduZWQgc2l6ZSwgaW50IGFjYyA9IDApCnsKICAgaWYgKCBzaXplID09IDAgKQogICAgICByZXR1cm4gYWNjIDsKICAgZWxzZQogICAgICByZXR1cm4gc3VtKGErMSwgc2l6ZS0xLCBhY2MgKyAqYSk7Cn0KCmludCBtYWluKCkKewogICBpbnQgYXJyYXlbXSA9IHsgMSwgMiwgMywgNCwgNSwgNiB9IDsKICAgdW5zaWduZWQgYXJyYXlfc2l6ZSA9IHN0ZDo6ZW5kKGFycmF5KSAtIHN0ZDo6YmVnaW4oYXJyYXkpIDsKCiAgIHN0ZDo6Y291dCA8PCBzdW0oYXJyYXksIGFycmF5X3NpemUpIDw8ICIgaXMgdGhlIHN1bSBvZiBlbGVtZW50cyBpbiBhcnJheS5cbiIgOwp9