代码如下
#include <iostream>
#include <stdlib.h>
using namespace std;
int reverse(int a)
{
int ans = 0, b = 0;
while(a)
{
b = a % 10;
ans = ans * 10 + b;
a /= 10;
b = 0;
}
return ans;
}
int main()
{
int num = 0, cnt = 0;
cin >> num;
while(num != reverse(num))
{
cout << num << " + " << reverse(num) << " = " << num + reverse(num) << endl;
num = num + reverse(num);
cnt++;
if(cnt == 10)
break;
}
if(cnt == 10)
{
cout << "Not found in 10 iterations.";
} else if(num == reverse(num))
{
cout << num << " is a palindromic number.";
}
system("pause");
return 0;
}