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

int main()
{
    int n;
    long long a;
    cin>>n;
    long long sum = 0;
    for(int i = 0 ; i < n ; i++)
    {
        cin>>a;
        sum+=a;
    }
    while(!(sum<=9 && sum>=0))
    {
        vector <int> d;
         long long temp = sum;
         long long z = 0;
        while(temp)
        {
            d.push_back(temp%10);
            temp = temp/10;
        }
        for(int i = 0; i <d.size(); i++)
        {
            z+=d[i];       
        }
        sum = z;
    }
    cout<<sum;
   

    return 0;
}
Copy
The Tale of a Generous Prince Abushukur
GNU G++17
48 ms
864 KB
Wrong Answer