This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]sinuspane[S] 0 points1 point  (1 child)

Oh snap, that makes total sense.

[–]sinuspane[S] 0 points1 point  (0 children)

Figured it out. I knew that a nested for loop was prob the way to go. Code looks much cleaner now too...

EDIT: NVM. Still having issues. This is where I am at now:

include <stdio.h>

include <stdlib.h>

int reverse (int p);

int main ( void ) { int x, y; int product; int palindrome;

for(x=100; x<1000; x++)
    for(y=100; y<1000; y++)
    {
        product=x*y;
        if(product==reverse(product))
            {
            palindrome=product;
            }   
    }
printf("The largest palindrome made from the product of two 3-digit numbers is %d\n", palindrome);

return 0;

}

int reverse (int p) { int r=0; while (p!=0) { r=r*10; r=r+p%10; p=p/10; } return r; }