The reverse and add function starts with a number, reverses its digits, and adds the reverse to the original. If the sum is not a palindrome, repeat this procedure until it does.
Write a program that takes number and gives the resulting palindrome (if one exists). If it took more than 1,000 iterations (additions) or yield a palindrome that is greater than 4,294,967,295, assume that no palindrome exist for the given number.
Input : 195 Output : 9339 Input : 265 Output: 45254 Input : 196 Output : No palindrome exist
This article is contributed by Rahul Agrawal. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Add index to characters and reverse the string
- Given a linked list, reverse alternate nodes and append at the end
- Reverse every word of the string except the first and the last character
- Find N numbers such that a number and its reverse are divisible by sum of its digits
- Split the array and add the first part to the end | Set 2
- Reverse a linked list
- Reverse a stack using recursion
- Reverse words in a given string
- Reverse a Linked List in groups of given size | Set 1
- Reverse alternate K nodes in a Singly Linked List
- Reverse Level Order Traversal
- Reverse alternate levels of a perfect binary tree
- Reverse a string without affecting special characters
- Merge two sorted linked lists such that merged list is in reverse order
- Different methods to reverse a string in C/C++
- Reverse an array in groups of given size
- Reverse an array in groups of given size | Set 2 (Variations of Set 1 )
- Collections.reverse() in Java with Examples
- Minimum edges to reverse to make path from a source to a destination
- Iteratively Reverse a linked list using only 2 pointers (An Interesting Method)
Improved By : Chandan_Kumar