answersLogoWhite

0

The most efficient method is to reverse the digits in the number and then check if the reversed number is equal to the original number. In C, we can implement this as follows (using long-hand notation for clarity). Note the use of base (defaulting to base 10) so that we can check values in other bases.

bool is_palindrome (unsigned num, unsigned base = 10) {

// local variables

unsigned rev, digit, digits;

// copy the input number

digits = num;

// initialise the accumulator

rev = 0;

// repeat while there are digits

while (digits) {

// extract the low-order digit using modulo (%) operator

digit = digit % base;

// shift the accumulated digits (if any) one position to the left

rev = rev * base;

// add on the new digit

rev = rev + digit;

// shift the remaining digits one position to the right

digits = digits / base;

} // end while

// return true if the number and its reverse are equal

return num == rev;

}

User Avatar

Wiki User

8y ago

What else can I help you with?

Related Questions

What is the smallest and biggest palindromic number?

Since a palindrome is just a number that reads the same way back and forth, the smallest palindrome would be 1. As there are an infinite number of palindromes (as you could just take any palindrome and simply place the same number in front of it and behind it, for example: 3, 939,99399,9993999,999939999, etc.), there is no biggest palindrome (infinity)


What is the palindrome for a distress call?

The palindrome for a distress call could be SOS.


Palindrome for related to citizenship?

A palindrome for "citizenship" could be: "hipcitizentic".


What is a palindrome for blow horn?

A palindrome for blowing a horn could be: 'toot'.


What is palindrome for related to citizenship?

A palindrome for "related to citizenship" could be "National."


What is a palindrome for male and female safe for kids to see?

A palindrome for "male" could be "elam," and a palindrome for "female" could be "emalf." Both are safe for kids to see and understand.


What is a palindrome for half a semi breve?

Minim is a palindrome for half a semi breve


Slang for mister palindrome?

Mr. Palindrome could be shortened to "Mr. Pali."


Palindrome for songs sung alone?

A palindrome is a word, phrase, number, or other sequence of characters that reads the same forward and backward. In the context of songs sung alone, a palindrome could be a song title or lyrics that are the same when sung in reverse. One example of a palindrome for songs sung alone could be "Able was I ere I saw Elba," which reads the same forwards and backwards.


Could you please confirm if you have completed the check-in process before you get in"?

"Have you finished checking in before entering?"


What is a palindrome for the noise of a bursting balloon?

A palindrome for the noise of a bursting balloon could be "pop."


What is a palindrome for Aramaic name for father?

A palindrome for the Aramaic name for father could be "Abba".