Source Code
#include<iostream>

using namespace std ;
int main()
{
  long long n; 
  cin>>n;
  long long num[n], sum =0 ;
  for(long long i= 0 ; i<n ;i++)
  {
    
      cin>>num[i];
      sum+=num[i];
  }
  long long sum2=0;
  long long temp=0;
 
if(sum <= 9)cout<<sum;
else
{
  while(1)
  {
      temp=sum%10;
      sum=sum/10;
      sum2=sum2+temp;
      
      if(sum==0)
      {
          if(sum2>=0 && sum2<=9)
          {
              cout<<sum2<<endl;
              return 0;
          }
          sum=sum2;
          sum2=0;
      }
  }
}
  
  
}
Copy
The Tale of a Generous Prince Joud
GNU G++17
92 ms
1.7 MB
Wrong Answer