Largest palindrome product | Project Euler | Problem #4

URL to the problem page: https://projecteuler.net/problem=4

A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 × 99.

Find the largest palindrome made from the product of two 3-digit numbers.



#include <iostream>
using namespace std;

int main()
{
    int i, j, units, tens, hundreds, thousands, tenthousands, hundredthousands, number, result = 0;
    for (i = 100; i < 1000; i++) {
        for (j = 100; j < 1000; j++) {
            number = i * j;
            units = number % 10;
            tens = (number % 100) / 10;
            hundreds = (number % 1000) / 100;
            thousands = (number % 10000) / 1000;
            tenthousands = (number % 100000) / 10000;
            hundredthousands = (number % 1000000) / 100000;
            if (units == hundredthousands && tens == tenthousands && hundreds == thousands) {
                if (number > result) {
                    result = number;
                }
            }
        }
    }
    cout << "Largest palindrome made from the product of two 3-digit numbers is  =  " << result << endl;
    return 0;

Comments

My photo
Ercan Tomac
instagram.com/ercantomac