Created
November 2, 2012 00:43
-
-
Save Rhomboid/3997891 to your computer and use it in GitHub Desktop.
project euler #4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
static bool is_palendrome(int n) | |
{ | |
if(n >= 100000) | |
return n / 100000 % 10 == n % 10 && | |
n / 10000 % 10 == n / 10 % 10 && | |
n / 1000 % 10 == n / 100 % 10; | |
else if(n >= 10000) | |
return n / 10000 % 10 == n % 10 && | |
n / 1000 % 10 == n / 10 % 10; | |
return false; | |
} | |
int main() | |
{ | |
int largest = 0; | |
for(int a = 100; a < 1000; a++) { | |
for(int b = 100; b < 1000; b++) { | |
int val = a * b; | |
if(is_palendrome(val) && val > largest) | |
largest = val; | |
} | |
} | |
std::cout << largest << std::endl; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment