程序代码如下:
#include<iostream>
using namespace std;
int overturn(int num) //求出你输出的数的倒序数,如:123,返回的倒序是:321
{
int num_over = 0; //倒序数的初值设置为0
while(num > 0) //循环的终止条件是num<=0
{
num_over = num_over * 10 + num % 10; // 不断地取原数的余数,反向排列
num = num / 10; //扔掉原数的最后一位,也是为了下一步取下一位余数
}
return num_over;
}
int main()
{
int num;
cout<<"\nInpout your num: ";
cin>>num;
if(overturn(num) == num)
cout<<"是回文数"<<endl;
else
cout<<"不是回文数"<<endl;
system("pause");
}