unsigned reverse (unsigned num) {
unsigned rev = 0;
while (num) {
rev *= 10;
rev += num % 10;
num /= 10;
}
return rev;
}
Reverse the digits then check of the new number is the same as the original number.
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; }
The smallest number that someone can get using the 91764 digits is 14679. The secret is to arrange the digits from the least number to their greatest number.
Standard Form
9,999,876 is the greatest seven-digit number using four different digits.
abdulrahman
You get the largest number if you sort the digits, from largest to smallest.
Using the digits 12279, the largest number that can be represented is 97,221.
7654321
8,754,321
Using while loop, write a program which calculates the product of digits from 1 to 5 and also show these no's vertically.
The steps for using a free reverse phone number lookup are: go to a website like Reverse Number Direct, type in the relevant information and then you'll get results.