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 29 30 31 32 33
|
#include <iostream>
using namespace std;
template <class T>
T sum(T array[], int beg, int end);
const int SIZE = 10;
int ary[SIZE] = {3, 4, 5, 6, 7, 8, 9, 10 , 11 , 12};
template <class T>
T sum(T array[], int beg, int end)
{
if(beg == end)
return ary[beg];
else
++beg;
return array[beg -1] + sum(array,beg,end - 1);
}
int main()
{
int summ;
int beg = 0;
int end = 0;
summ = sum(ary,beg, end);
cout << "The sum of the array is: " << summ << endl;
return 0;
}
|