Similar to: http://stackoverflow.com/questions/3250957/finding-the-largest-palindrome-of-the-product-of-two-three-digit-numbers-problem The IsPalindrome condition always is true.Please guide me to the error.
#include <stdio.h>
#include <malloc.h>
int IsPalindrome(int num);
int main()
{
int i,j,temp;
for(i=10;i<99;i++)
{
for(j=10;j<99;j++)
{
if(IsPalindrome(i*j))
temp=i*j;
}
}
printf("%d\n",temp);
getch();
return 0;
}
int IsPalindrome(int num)
{
int x,i,j,flag;
char p[50];
/*Convert the number into an array*/
/*Avoid p index 0 for simplicity*/
/*Converting number into array*/
for(i=1;x==0;i++)
{
x=num%10;
p[i]=x;
}
/*Checking for palindrome,length of array is i*/
for(j=0;j<i/2;j++)
{
if(*(p+j)!=*(p+i-j))
flag=0;
}
return flag;
}