UVA 10018 - Reverse and Add
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=959
<h1> Solution: </h1>
#include<bits/stdc++.h>
int main()
{
long long n,a,s,c;
int t,i;
scanf("%d",&t);
while(t--){
scanf("%lld",&n);
a=n;c=0;
while(1){
s=0;
while(n!=0)
{
s=s*10+n%10; // revere the number.....
n/=10;
}
if(s==a)
break;
else
{
n=s+a;
a=s+a; // add the number with the revers number....
c++;
}
}
printf("%lld %lld\n",c,a);
}
return 0;}
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=959
<h1> Solution: </h1>
#include<bits/stdc++.h>
int main()
{
long long n,a,s,c;
int t,i;
scanf("%d",&t);
while(t--){
scanf("%lld",&n);
a=n;c=0;
while(1){
s=0;
while(n!=0)
{
s=s*10+n%10; // revere the number.....
n/=10;
}
if(s==a)
break;
else
{
n=s+a;
a=s+a; // add the number with the revers number....
c++;
}
}
printf("%lld %lld\n",c,a);
}
return 0;}