找出11-999间的回文数m,m方,m三次方均为回文

判断是否为回文:将数反序,反序后的书与原来的数一样即是回文

#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;
}

输出结果:

发布了24 篇原创文章 · 获赞 7 · 访问量 3777

猜你喜欢

转载自blog.csdn.net/qq_39980334/article/details/104237669
M
^M