Project Euler #4: Finding the largest palindrome that is a product of two 3-digit numbers Amateur c++ programmer here, working my way through the Project Euler problems (problem 4). I would love for someone to take a look at my ~40 lines of code and give suggestions on improving the effectiveness of the code, and how/what to change to better follow the general guidelines for the flow of a c++ program.
The task states as such: &quot;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.&quot;
// Largest palindrome product (4)
#include &lt;iostream&gt;
#include &lt;time.h&gt;
bool is_palindrome(int &amp;num) { // Determine if a given number is a palindrome or not
    int reverse=0, copy=num, digit;
    do {
        digit = copy % 10;
        reverse = reverse*10 + digit;
        copy /= 10;
    } while (copy != 0);
    return (reverse == num);
}
int main(void) {
    double time_spent = 0.0;
    clock_t begin = clock();

    int largest_palindrome = 0;
    for (int i=999; i&gt;99; i--) {
        for (int j=999; j&gt;99; j--) {
            if (i &lt; largest_palindrome/1000) { // Optimalization
                // std::cout &lt;&lt; &quot;Any value lower than &quot; &lt;&lt; i &lt;&lt; &quot; will, when multiplied by 999, never exceed the largest palindrome (&quot; &lt;&lt; largest_palindrome &lt;&lt; &quot;).&quot;&lt;&lt; '\n';
                std::cout &lt;&lt; &quot;No larger palindromes possible.&quot; &lt;&lt; '\n';
                i = 0;
                j = 0;
            } else {
                int product = i*j;
                if (is_palindrome(product) &amp;&amp; product&gt;largest_palindrome) {
                    std::cout &lt;&lt; &quot;Found palindrome! &quot; &lt;&lt; i &lt;&lt; &quot; * &quot; &lt;&lt; j &lt;&lt; &quot; == &quot; &lt;&lt; product &lt;&lt; '\n';
                    largest_palindrome = product;

                    // More optimalization (no product of the current iteration of i can be larger than the current palindrome, so skip to next iteration)
                    j = 0;
                }
            }
        }
    }

    // Program execution time
    clock_t end = clock();
    time_spent += (double)(end - begin) / CLOCKS_PER_SEC;
    std::cout &lt;&lt; &quot;Elapsed time is &quot; &lt;&lt; time_spent &lt;&lt; &quot; seconds.&quot; &lt;&lt; std::endl;
    return 0;
}
Here are some suggestions in addition to the existing answers.
&lt;chrono&gt;
In general, the C++ std::chrono API is more flexible and
type-safe than the C functions in &lt;ctime&gt;, so consider using
std::chrono to time the function.
is_palindrome
In C++, it is usually not advised to declare multiple variables on one
line.  Taking small types like int by value is more efficient than
by reference and gives you a free copy to use.  To prevent errors, I
would also add an assertion to ensure that the input is a nonnegative
integer:
bool is_palindrome(int number) {
    assert(number &gt;= 0);

    int original = number;
    int reversed = 0;

    while (number &gt; 0) {
        reversed *= 10;
        reversed += number % 10;
        number /= 10;
    }

    return reversed == original;
}

Note that your version suffers from overflow problems for certain
large values of number, which this version does not fix.
Mathematical optimizations
By analyzing the problem mathematically, some optimizations can be
achieved.  The largest product of two 3-digit numbers is \$ 999 \times
999 = 998001 \$, so the answer will be at most a six-digit number.
For now, let's just assume that the answer is \$ \ge 900000 \$.  Thus,
the palindromes are restricted to the form \$ 9abba9 \$, where \$a\$
and \$b\$ are single-digit numbers.
By applying the divisibility rule for \$11\$, we see that \$
9abba9 \$ is a multiple of \$11\$.  Therefore, at least one of the
3-digit factors is a multiple of \$11\$ — we'll call this factor
the primary factor.  Since the product is an odd number, the primary
factor is odd as well, so we can start from \$979\$, the largest odd
3-digit multiple of \$11\$, and subtract \$22\$ at a time.  Our search
would stop if the primary factor becomes lower than \$900\$, since
\$899 \times 999 = 898101 &lt; 900000\$, meaning our assumption would be
invalid.
Here's my result:
#include &lt;algorithm&gt;
#include &lt;cassert&gt;
#include &lt;climits&gt;
#include &lt;iostream&gt;

bool is_palindrome(int number) {
    assert(number &gt;= 0);

    int original = number;
    int reversed = 0;

    while (number &gt; 0) {
        reversed *= 10;
        reversed += number % 10;
        number /= 10;
    }

    return reversed == original;
}

int main() {
    int max_product = INT_MIN;

    for (int primary = 979; primary &gt;= 900; primary -= 22) {
        for (int secondary = 999; secondary &gt;= 900; secondary -= 2) {
            int product = primary * secondary;

            if (is_palindrome(product)) {
                max_product = std::max(product, max_product);
                break; // break out of the inner loop
            }
        }
    }

    if (max_product &lt; 900000) {
        std::cout &lt;&lt; &quot;No result &gt;= 900000\n&quot;;
    } else {
        std::cout &lt;&lt; &quot;Found: &quot; &lt;&lt; max_product &lt;&lt; '\n';
    }
}

(wandbox)
The result is 906609, which is correct.