Thursday, 14 August 2014

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

//answer=906609
int palan(int a)
{
int n=5;
int g[6];
int m=0;
while(n>=0)
{
g[n]=a%10;
a/=10;
n--;
}
n=0;
while(n<=2)
{
if(g[n]==g[5-n]){m++;}
n++;
}
if(m==3){return 1;}
else{return 0;}
}



#include<math.h>
main()
{
int x=100;
int y=100;
int a,large,b,c;
int pal=0;
int max=0;
while(x<=999)
{
while(y<=999)
{
a=x*y;
int n=palan(a);
if(n==1){

    if(a>max){max=a;}
}
 y++;
}
y=100;
x++;
}
printf("%d",max);

}








No comments:

Post a Comment