Source Code
#include<iostream>
using namespace std;
int a[100000];
int ret(int s) {
	
		int sum = 0;
		while (s > 0 || sum > 9) {
			if (s == 0) {
				s = sum;
				sum = 0;
			}
			sum += s % 10;
			s /= 10;
		}
		return sum > 9 ? ret(s) : sum;
}
int main() {
	int n;
	cin >> n;
	int x = 0;
	for (int i = 0;i < n;i++)
	{
		cin >> a[i];
		x += a[i];
	}
	cout<<ret(x);
	
	
	}




	
Copy
The Tale of a Generous Prince hadeelYasir
GNU G++17
18 ms
1.2 MB
Wrong Answer