Adding Reversed Numbers
#include<iostream>
using namespace std;
int main()
{
int t;
cin>>t;
while(t!=0)
{
int m,n,revm=0,revn=0,sum=0,rev=0;
cin>>m>>n;
while(m!=0)
{
revm=revm*10+m%10;
m=m/10;
}
while(n!=0)
{
revn=revn*10+n%10;
n=n/10;
}
sum=revm+revn;
while(sum!=0)
{
rev=rev*10+sum%10;
sum=sum/10;
}
cout<<"\n"<<rev;
t--;
}
return 0;
}
#include<iostream>
using namespace std;
int main()
{
int t;
cin>>t;
while(t!=0)
{
int m,n,revm=0,revn=0,sum=0,rev=0;
cin>>m>>n;
while(m!=0)
{
revm=revm*10+m%10;
m=m/10;
}
while(n!=0)
{
revn=revn*10+n%10;
n=n/10;
}
sum=revm+revn;
while(sum!=0)
{
rev=rev*10+sum%10;
sum=sum/10;
}
cout<<"\n"<<rev;
t--;
}
return 0;
}
No comments:
Post a Comment