For any given number:
n = num;
rev = 0;
while (num > 0)
{
dig = num % 10;
rev = rev * 10 + dig;
num = num / 10;
}
If n == rev
then num
is a palindrome:
cout << "Number " << (n == rev ? "IS" : "IS NOT") << " a palindrome" << endl;
More Related Contents:
- How can I pair socks from a pile efficiently?
- Unique (non-repeating) random numbers in O(1)?
- What is tail call optimization?
- Is there an O(n) integer sorting algorithm?
- Determine font color based on background color
- Nearest neighbors in high-dimensional data?
- What algorithm gives suggestions in a spell checker?
- How can I measure the similarity between two images? [closed]
- Algorithm to generate anagrams
- Generate all unique substrings for given string
- Sum-subset with a fixed subset size
- design a stack such that getMinimum( ) should be O(1)
- How to check if line segment intersects a rectangle?
- How to read values from numbers written as words?
- Calculate largest inscribed rectangle in a rotated rectangle
- Find the first un-repeated character in a string
- How to partition an array of integers in a way that minimizes the maximum of the sum of each partition?
- 3 dimensional bin packing algorithms
- What is a bubble sort good for? [closed]
- Iterating over a Binary Tree with O(1) Auxiliary Space
- How do I find a factorial? [closed]
- Best way of calculating n choose k?
- Peak detection of measured signal
- “Rounding” colour values to the nearest of a small set of colours
- Algorithm for permutations of operators and operands
- Convert light frequency to RGB?
- Best way to find a point on a circle closest to a given point
- Algorithm for iterating over an outward spiral on a discrete 2D grid from the origin
- Tournament bracket placement algorithm
- Postfix notation to expression tree