判断是否为回文:将数反序,反序后的书与原来的数一样即是回文
#include "stdafx.h"
#include<iostream>
using namespace std;
bool symm(unsigned n);
int _tmain(int argc, _TCHAR* argv[])
{
for(unsigned m=11;m<=999;m++)
if(symm(m)&&symm(m*m)&&symm(m*m))
{
cout<<"m="<<m<<" ";
cout<<"m*m="<<m*m<<" ";
cout<<"m*m*m="<<m*m*m<<endl;
}
system("pause");
return 0;
}
//判断是否为回文
bool symm(unsigned n)
{
unsigned i=n;
unsigned m=0;
while(i>0)
{
m=m*10+i%10;
i/=10; //除10取整
}
return m==n;
}
输出结果: