Saturday, 17 August 2013

Calculate the highest palindrome that is the product of two 3-digit numbers

Calculate the highest palindrome that is the product of two 3-digit numbers

I'm stuck on Euler#4 which is to calculate the highest palindrome number
by product of two 3-digit numbers. The answer I'm getting is always 0.
Evidently help is required.
#include <stdio.h>
#include <conio.h>
int main()
{
int i,j,h=0,m=0,p=0;
clrscr();
for(i=100;i<1000;i++)
{
for(j=100;j<1000;j++)
{
p=i*j;
h=p/100000;
m=p%10;
if(h==m)
{
h=(p/10000)%10;
m=(p/10)%10;
if(h==m)
{
h=(p/1000)%10;
m=(p%1000)/100;
if(h==p)
{
printf("%d\n",p);
}
}
}
}
}
return 0;
}

No comments:

Post a Comment