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.
#include <iostream>
#include <cmath>
bool check(int target)
{
//std::cout<<target<<std::endl;
int i=6;
int j=0;
int temp=0;
int out=0;
int hehe;
hehe=target;
if ((int)pow(10, i)>target)
{
//std::cout<<pow(10,i)<<std::endl;
i--;
}
while(target!=0)
{
temp = target /(int)(pow(10, i));
out=out+temp*pow(10,j);
//std::cout<<out<<std::endl;
target=target-temp*pow(10,i);
i--;
j++;
}
//std::cout<<out<<std::endl;
if(out==hehe)
{
std::cout<<out<<" YES"<<std::endl;
return (true);
}
else
return(false);
}
int main2()
{
//check(12345)==true;
long sum,temp;
int i,j;
i=j=999;
temp=0;
int tempx,tempy;
for(i=100;i<=999;i++)
{
for(j=100;j<=999;j++)
{
//std::cout<<i<<" "<<j<<std::endl;
sum=i*j;
if(check(sum)==true)
{
if(sum>=temp)
{
temp = sum;
tempx=i;
tempy=j;
}
}
}
}
std::cout<<temp<<" "<<tempx<<" "<<tempy<<" "<<std::endl;
}
int main()
{
//check(906609);
main2();
}