Project Euler prob 4 in c?

I have come up with this code for solving the problem but the output displays the largest palindrome as 0. I don’t understand the issue. Need help. I have just started basic C coding and I am not able to understand the fault with the following code:

#include<stdio.h>

int main()
{

int i=100,j=100,prod,temp,rev=0,rem,l,m,max=0;
for(;i<1000;i++)
{
    for(;j<1000;j++)
    {
        prod=i*j;
        temp=prod;
        while(temp!=0)
        {
           rem=temp%10;
           rev=(rev*10)+rem;
           temp=temp/10;
        }
        if(rev==prod)
        {
            if(prod>max)
            {
                max=prod;
                l=i;
                m=j;
            }
        }


    }
}
printf("nThe largest number which is a palindrome and is a product of two 3 digit numbers is: %d and is the product of numbers %d and %dn",max,l,m);
return 0;
}


Source: c#

Leave a Reply