It gives correct submission for wrong code.WHY??

So, it will give me correct submission in this code for the problem CodeChef: Practical coding for everyone even though if i input single digit it gives wrong output:-
#include
using namespace std;

int main() {
int t;
cin>>t;
while(t–){
int n;
cin>>n;
int a=n%10;
while(n>=10){
n=n/10;
}
int k=a+n;
cout <<k<<endl;

}
return 0;

}

On the other hand in the code where i have taken care of this problem it gives wrong answer:-
#include
using namespace std;

int main() {
int t;
cin>>t;
while(t–){
int n;
cin>>n;
if(n>=10){
int a=n%10;
while(n>=10){
n=n/10;
}
int k=a+n;
cout <<k<<endl;}
else{
cout<<n<<endl;
}

}
return 0;

}

Hi, in the question it is mentioned to find sum of first and last digit of given integer so, if we are given a single-digit integer the number itself is first and last number. If input is 1, then output should be 1+1=2.

The second code mentioned above doesn’t work because of this if condition here:

if(n>=10){
int a=n%10;
while(n>=10){
n=n/10;
}

If the number is less than 10 then int a never gets declared and no value is then added in this operation int k=a+n; so k here simply equals to n.