Source Code
#include<iostream>

using namespace std ;
int main()
{
  int n; 
  cin>>n;
  long long num[n], sum =0 ;
  for(int i= 0 ; i<n ;i++)
  {
    
      cin>>num[i];
      sum+=num[i];
  }
  int sum2=0;
  int 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
79 ms
1.7 MB
Wrong Answer