Source Code
#include <iostream>
using namespace std;
#define ll long long int

long long int sum_of_digits(ll number) {
	ll sum = 0;
	while (number != 0) {
		sum += number % 10;

		number = number / 10;
	}
	return sum;
}

int main() {
	ll sum = 0, number;
	ll n;
	cin >> n;
	while (n--) {
		cin >> number;
		sum += sum_of_digits(number);
	}
	number = sum;
	while (number >= 10) {
		number = sum_of_digits(number);
	}
	cout << number << endl;
}




Copy
The Tale of a Generous Prince Rokii
GNU G++17
77 ms
940 KB
Accepted