167. Summing Digits

 avatar
user_6817964
c_cpp
2 years ago
256 B
1
Indexable
Never
int f(int n);

int f(int n) {
	if (n / 10 > 0) {
		int sum = 0;
		while (n > 0) {
			sum += n % 10;
			n /= 10;
		}
		f(sum);
	}
	else {
		return n;
	}
}

int main() {

	int n;
	scanf("%d", &n);
	printf("%d\n", f(n));
	return 0;

}