Hello, I attempted the ADDREV question, HERE. My code gives matches the example output for the example input, but gives a wrong answer when submitted. Please can you look into it and help me find whats wrong.
CODE:
#include<iostream>
#include<math.h>
using namespace std;
//funtion for reversing the number
int rev_num(int n){
if(n==0) return 0;
int result=0,digits=0,temp;
temp=n;
// getting number of digits for n
while(temp!=0){
temp=temp/10;
digits++;
}
//reversing the number
for(int i=0;i<digits;i++){
int rem=0;
rem=n%10;
n=n/10;
result=result+rem*pow(10,digits-i);
}
//removing any tailing zeros
while(result%10==0){
result=result/10;
}
return result;
}
int main(){
int t;
cin>>t; //number of testcases
for(int i=0;i<t;i++){
int a,b,ra,rb,rsum,output;
cin>>a>>b; // the two numbers
ra=rev_num(a);
rb=rev_num(b);
rsum=ra+rb;
output=rev_num(rsum);
cout<<output<<"\n";
}
}