1
Name:
Anonymous
2010-10-06 22:16
I'm trying to do problem 4 on Project Euler but something isn't going well.
If you could review my code to tell me what I'm doing wrong.
http://pastebin.ca/1956037
4
Name:
Anonymous
2010-10-07 4:53
EXPERT C SOLUTION
// pipe output through sort -n
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int ispalindrome(char *s) {
char *sr,*p,*pr;
int r;
sr = strdup(s);
pr = sr + strlen(s);
*pr-- = 0;
for(p=s;*p;p++,pr--)
*pr = *p;
r = strcmp(s,sr);
free(sr);
return !r;
}
int main() {
int x,y;
char s[64];
for(x=999;x;x--) {
for(y=999;y;y--) {
sprintf(s,"%d",x*y);
if(ispalindrome(s))
printf("%s\n",s);
}
}
return 0;
}