如11,它的平方是121,立方是1331,都是迴文數。
所謂三重回文數a是指a,a*a,a*a*a都是迴文數字。實例如下:
#include <stdio.h>
long reverse(int n)
{
long m,j=0;
m = n;
while(m){
j = j*10 + m%10;
m = m/10;
}
return j;
}
long isCircle(long n)
{
long m;
m = reverse(n);
if(m == n)
return 1;
else
return 0;
}
void palindrome(int low,int high)
{
long i;
for(i=low; i<=high; i++){
if(isCircle(i)&& isCircle(i*i)&& isCircle(i*i*i))
printf("%ld ",i);
}
}
int main(int argc, char *argv[])
{
printf("the palindrome numbers between 11~999 are\n");
palindrome(11,999);
printf("\n");
return 0;
}
程式執行結果如下:
peng@ubuntu:~/src/test/c/suanfa/miaoqu$ gcc 6.9.c
peng@ubuntu:~/src/test/c/suanfa/miaoqu$ ./a.out
the palindrome numbers between 11~999 are
11 101 111
這樣有個實例,更加的清楚 三重回文數了!!!!