Source Code
#include <iostream>
using namespace std;

int main() {
	int n, sum = 0, temp;
	cin >> n;
	while (n--) {
		cin >> temp;
		sum += temp;
	}
	
	if (sum < 10) {
		cout << sum;
		return 0;
	}
	
	int ans = sum;
	while (ans >= 10) {
		sum = 0;
		while (ans >= 1) {
			sum += ans % 10;
			ans /= 10;
		}
		ans = sum;
	}
	
	cout << ans;
}
Copy
The Tale of a Generous Prince Dana
GNU G++17
3 ms
636 KB
Wrong Answer