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;
}