>>1
First of all, no exceptions.
Half the Euler problems are really just quizzes on whether you know what the totient function does, the other half stretch from easy banalities like this one to later problems where a naïve implementation takes longer to run than it does to go back and fix.
This is what I mean by "banality"...
ispal x = s == reverse s where s = show x
main = print . maximum . filter ispal $
[x*y | x <- [100..999], y <- [100..999]]
or, if you are a masochist...
#include <stdio.h>
struct s {
struct s *next;
unsigned int x, y;
};
int main(int argc, char *argv[])
{
struct s s[900], *p, *a, *b, *c;
unsigned int i, j, d[6], x;
for (i = 100; i <= 999; ++i) {
j = i - 100;
s[j].x = i;
s[j].y = i * i;
s[j].next = &s[j-1];
}
s[0].next = 0;
p = &s[899];
while (1) {
for (x = p->y, i = 0; x; x /= 10, ++i)
d[i] = x % 10;
for (j = 0, i = i - 1; j < i; ++j, --i)
if (d[i] != d[j])
break;
if (j >= i) {
printf("%u\n", p->y);
return 0;
}
x = (p->y -= p->x);
a = p;
b = p->next;
while (b->y > x) {
a = b;
b = b->next;
}
if (a != p) {
c = p->next;
a->next = p;
p->next = b;
p = c;
}
}
}
I don't see why you need so much damn code just to check if a number is a palindrome. Oh, and don't forget to include
<stdbool.h>, you seem to have the
#define TRUE sickness infesting your code.