Hi, so I'm trying to get the highest palindromic number from the results of a 3digit multiplied by 3 digit result. Aka 1*1 - 999*999, or any combination of those numbers.
I think there's some weird undefined behaviour going on, because I swear that I saw 2 different results from the same run. The problem is, it's giving a 7 digit result (And it's not a palindromic number). 999*999 is a 6 digit number, therefore it's impossible for the result to be a 7 digit number... So something really strange is going on, and I can't see what's wrong. Here's the code:
Code:
#include <iostream>
#include <string>
using namespace std;
int main() {
char * string = new char[30];
int highest = 0;
int temp = 0;
for (int x = 0; x < 1000; x++)
for (int y = 0; y < 1000; y++) {
itoa(x * y, string, 10);
if ( ((int)string[0] == (int)string[5]) && ((int)string[1] == (int)string[4]) )
if ((int)string[2] == (int)string[3])
temp = (int)string;
if (highest < temp)
highest = temp;
}
cout << highest << endl;
}
Cheers.