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

unsigned digitSum(unsigned x) {
	if (x == 0)
		return 0;
	else
		return x % 10 + digitSum(x / 10);
}

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

	std::cout << digitSum(num) << std::endl;

	return 0;
}