Function: find and output number between 11 to 999 m, which satisfies m, M2 and m3 are palindrome.
The so-called Palindrome refers to the digits bilaterally symmetrical integer, e.g. 121,676,94249 like. Satisfying the above conditions as the number m = 11, m2 = 121, m3 = 1331 are all palindrome.
Please prepare function int svalue (long m) to achieve this function, if it is a palindrome, the function returns 1, returns 0 otherwise. After the output to a file in out.dat.
#include <stdio.h>
int jsValue(long n)
{int i,strl,half; char xy[20];
ltoa (n, xy, 10) ; / Note Itoa not be used here () function, as is a long n-type / strl = strlen (xy);
half=strl/2;
for(i=0;i<half;i++)
if(xy[i]!=xy[–strl]) break;
if(i>=half) return 1;
else return 0;
}
main()
{long m;
FILE *out;
out=fopen(“out.dat”,“w”);
for(m=11;m<1000;m++)
{
if(jsValue(m)&&jsValue(mm)&&jsValue(mm*m))
{ printf("m=%4ld,mm=%6ld,mmm=%8ld \n",m,mm,mmm);
fprintf(out,"m=%4ld,mm=%6ld,mmm=%8ld \n",m,mm,mmm);
}
}
fclose(out);
system(“pause”);
}
Or the following solution:
int jsValue(long n)
{long int s=0,k;
k=n;
while(k)
{P = p * + 10 to 10%;
k/=10;
}
if(s==n) return 1;
if(s!=n) return 0;
}
The output is:
m= 11,mm= 121,mm*m= 1331
m= 101,mm= 10201,mm*m= 1030301
m= 111,mm= 12321,mm*m= 1367631