1 / 3
Jan 2018

what is the error in my code of ADDING REVERSED NUMBERS?
#include
#include<bits/stdc++.h>
using namespace std;
int rev(int num);
int main()
{
int n,i=0,j=0,a,b,ar,br,c,cr;
cin>>n;

while(n!=0)
{
    cin>>a  >>b;
    while(a%10==0)
        {a=a/10;}
    
        ar=rev(a);
        
        
    while(ar%10==0)
        {ar=ar/10;}



    while(b%10==0)
        {b=b/10;}
        
        br=rev(b);
        
        
    while(br%10==0)
        {br=br/10;}

    c=a+b;


    while(c%10==0)
        {c=c/10;}
        
        cr=rev(c);
        
        
    while(cr%10==0)
        {cr=cr/10;}


    cout<<cr<<endl;
    n--;
    
}



return 0;

}

int rev(int num)
{
int rev_a=0;
while(num>0)
{
rev_a=rev_a *10+num%10;
num=num/10;
}

return rev_a;

}

  • created

    Jan '18
  • last reply

    Jan '18
  • 2

    replies

  • 1.2k

    views

  • 2

    users

Can you explain what your code is doing.
for example
1
123 300
Correct output is 423.
and yours is 621.