Source Code
#include<iostream>
#include <math.h>
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];
  }
if(sum <= 9)cout<<sum;
else
{
    while(sum >9)
    {
    long long temp = 0 ; 
  while(sum >0)
  {
      temp +=sum%10;
      sum/=10;
  }
  sum = temp ;   
    }
    cout<<sum;
}
  
  
}
Copy
The Tale of a Generous Prince Joud
GNU G++17
56 ms
1.7 MB
Wrong Answer