Skip to content

Instantly share code, notes, and snippets.

@cengiz-io
Created August 9, 2015 12:04
Show Gist options
  • Select an option

  • Save cengiz-io/1441b39f3f8a9f31f8a3 to your computer and use it in GitHub Desktop.

Select an option

Save cengiz-io/1441b39f3f8a9f31f8a3 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <sstream>
using namespace std;
bool isPalindrome(int n) {
int reversedN = 0;
stringstream originalStr;
originalStr << n;
stringstream reversedStr;
reversedStr << string(originalStr.str().rbegin(), originalStr.str().rend());
reversedStr >> reversedN;
return n == reversedN;
}
int main() {
int largestPalindrome = 0;
for (int x = 800; x < 1000; x++) {
for (int y = 800; y < 1000; y++) {
int product = x * y;
if (isPalindrome(product) && product > largestPalindrome) {
largestPalindrome = product;
}
}
}
cout << largestPalindrome << endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment