Okay, basically what I have to do is find the products of X times Y, where X and Y are integers which are greater than 0 and less than 1000.
From these products find the sum of any which are palindromes.
My code which is included below seems fine with me, however I keep getting a wrong answer (393705315), I was told the correct answer is a nine digit number starting with a 5. Anything wrong with the code?
------------------------------------------
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <conio.h>
long int prod,sum;
int x,y,q,z,len;
char store[7],reverse[7];
int main() {
sum=0;
for (x=1; x<1000; x++) {
for (y=1; y<1000; y++) {
prod = x*y;
itoa(prod,store,10);
len = strlen(store);
q = 0;
for (z=(len-1); z>=0; z--) {
reverse[q] = store[z];
q++;
}
if (atoi(store) == atoi(reverse)) {
sum = sum + (x*y);
}
}
}
printf("Done. %d",sum);
getch();
return 0;
}
--------------------------------------
From these products find the sum of any which are palindromes.
My code which is included below seems fine with me, however I keep getting a wrong answer (393705315), I was told the correct answer is a nine digit number starting with a 5. Anything wrong with the code?
------------------------------------------
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <conio.h>
long int prod,sum;
int x,y,q,z,len;
char store[7],reverse[7];
int main() {
sum=0;
for (x=1; x<1000; x++) {
for (y=1; y<1000; y++) {
prod = x*y;
itoa(prod,store,10);
len = strlen(store);
q = 0;
for (z=(len-1); z>=0; z--) {
reverse[q] = store[z];
q++;
}
if (atoi(store) == atoi(reverse)) {
sum = sum + (x*y);
}
}
}
printf("Done. %d",sum);
getch();
return 0;
}
--------------------------------------