Website Summary Files Commits Branches @commit @diff @stats
path: root / Week13 / Exercise10.cpp
blob: 5d71e4fac8cf152fb25b752604aff726b076d1ed (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <iostream>

double sum(double totalsum, const double* elems, unsigned size) {
	if (size == 0)
		return totalsum;
	else
		return sum(totalsum + *elems, elems + 1, size - 1);
}

int main() {
	unsigned size;
	std::cin >> size;

	double* arr = new double[size];
	for (unsigned i = 0; i < size; ++i)
		std::cin >> arr[i];

	std::cout << sum(0.0, arr, size) << std::endl;

	free(arr);

	return 0;
}