Print number with highest sum of digits - C++

Q. Write a C++ program to read 'n' numbers and print the number with maximum sum of digits.

Answer:

#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
    int n, i, no, sum;
    cout<<"\n Enter No. of Elements  : ";
    cin>>n;
    cout<<" --------------------------------------------";
    int arrNo[n], arrSum[n];
   
    for(i=0; i<n; i++)
    {
        cout<<"\n Enter " << i+1 << " No.   : ";
        cin>>arrNo[i];
    }   
    //Calculating digit sum
    for(i=0; i<n; i++)
    {
        sum = 0;
        no = arrNo[i];
        while(no != 0)
        {
            sum += no%10;
            no/=10;
        }
        arrSum[i] = sum;    
    }    
    //Displaying Sum of Digits
    cout<<"\n --------------------------------------------";
    cout<<"\n Sum of Digits";
    cout<<"\n --------------------------------------------";
    for(i=0;i<n;i++)
    {
         cout<<" ";
         cout<<"\n Sum of No.["<<i+1<<"] :  "<<arrSum[i]<< "\n";
    }
    //Sort function for displaying number whose addition is largest
    sort(arrNo, arrNo+n, greater<int>());
    cout<<"\n --------------------------------------------";
     //displaying digit whose addition is largest  
    cout<<"\n Number whose Addition is Largest  : "<<arrNo[no];

    //Sort function for displaying largest sum of digit
    sort(arrSum, arrSum+n, greater<int>());
    cout<<"\n Largest Sum is                    : "<<arrSum[no];  //displaying largest sum of digit   

    return 0;
}


Output:

sum digit largest number