Is an integer number a palindrome?

· Read in about 1 min · (107 Words)

What is a palindrome anyway? Wikipedia states:

A palindrome is a word, phrase, number, or other sequence of units that may be read the same way in either direction, with general allowances for adjustments to punctuation and word dividers.

There are many solutions of the question, but I thought I would give it a shot. I specifically didn’t want to use recursion.

Here is what I came up with:

bool IsPalindrome(unsigned int num)
{
    unsigned int number = num;
    unsigned int tmpn = 0;
    while (number > 0)
    {
        tmpn = 10 * tmpn + number % 10;
        number /= 10;
    }
    return tmpn == num;
}