Source Code
#include<string>
#include <iostream>
using namespace std;


int main() {


	int n = 0, sum = 0, a[100000], num = 0;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		sum = sum + a[i];
	}
	if (sum < 10)
	{
		cout << sum;
		return 0;
	}

	while (sum != 0) {
		num = num + (sum % 10);
		sum = sum / 10;

		//num = num + sum;
		if (sum == 0 && num >= 10)
		{

			sum = num;
			num = 0;
		}


	}
	cout << num;




}
Copy
The Tale of a Generous Prince hatamleh
GNU G++17
3 ms
788 KB
Wrong Answer