不用别人认可也不用别人理解,尽情去做自己认为应该做的事……

2009年5月6日星期三

Problem 4--(c)

Problem 4

16 November 2001

A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 × 99.

Find the largest palindrome made from the product of two 3-digit numbers.


Answer:
906609

code:

#include
int PD(int num)
{
if(num>99999)
{
if((num/100000==num%10)&&((num%100000)/10000==(num%100)/10)&&(num/1000%10==(num%1000)/100))
return 1;
else
return 0;
}
else
{
if((num/10000==num%10)&&(num%10000)/1000==(num%100)/10)
return 1;
else
return 0;
}
}
int main(void)
{
int i,j,max=10000;
for(i=999;i>99;i--)
for(j=999;j>99;j--)
if(PD(i*j)==1&&i*j>max)
max=i*j;
printf("%d\n",max);
return 0;
}

0 评论: