+ 1

Is it possible to reverse a number ending with 0 in C++

Hi everyone, so, I just did a code coach about Palindrome numbers, so I successfully completed the challenge and I managed to reverse various numbers in my code, but I was curious about if we input a number ending with zero. The results is that I couldn't really get a completely reversed number for numbers ending or starting with zeros, e.g: 120 becomes 21 and 050 becomes just 5. https://code.sololearn.com/cn2HO5eYeFwy/?ref=app

10th Aug 2021, 10:56 PM
Rashid Shakili
Rashid Shakili - avatar
5 Respostas
+ 5
Numbers should behave this why but you could work with strings
10th Aug 2021, 11:33 PM
Abs Sh
Abs Sh - avatar
+ 1
Yes . But it takes time and memory...you have to find the length of the number then create an array using that length then store each digit into the array then again check in the reverse way if it's equal or not......Or you have to convert it to string of characters then reverse and check both ways are little complicated and time taken
11th Aug 2021, 4:40 AM
Arun Ruban SJ
Arun Ruban SJ - avatar
+ 1
Martin Taylor well I have seen your code it's interesting, but still if you input 050 the output is 50 is NOT a palindrome. So it doesn't work as I expect it to.
14th Aug 2021, 4:04 PM
Rashid Shakili
Rashid Shakili - avatar