+ 3

Find reverse in C++

i want to find reverse of a number in C++ using numeric data types which return 0 in case of overflow. for example we take int as 4 bytes it stores signed 2147483647 number let we reverse this number it becomes 7463847412 it beyonds the range of int in this case it should return 0 how to handle it

10th Sep 2017, 4:26 AM
Azam
Azam - avatar
9 ответов
+ 2
here is my try Here is a likely bruteforce see this https://code.sololearn.com/curvKsv91799/?ref=app
10th Sep 2017, 5:40 AM
Azam
Azam - avatar
+ 4
https://code.sololearn.com/cnBXWW4YriE8/?ref=app
10th Sep 2017, 4:29 AM
Nomeh Uchenna Gabriel
Nomeh Uchenna Gabriel - avatar
+ 3
great @Azam, but unlike Maria's code, it doesn't work with negative numbers just like mine https://code.sololearn.com/W0BN8HZm8F1k/?ref=app
10th Sep 2017, 6:11 AM
Nomeh Uchenna Gabriel
Nomeh Uchenna Gabriel - avatar
+ 3
ohhh you use an array in JS unlike Cpp
10th Sep 2017, 6:21 AM
Azam
Azam - avatar
+ 2
I input 2147483647 answer is -1126087180 in Maria's code @Nomeh
10th Sep 2017, 5:03 AM
Azam
Azam - avatar
+ 2
yeah it's quit easier and shorter with arrays and loops. ...I think the same syntax should work with other languages like (C++, Java, C#, Swift etc)
10th Sep 2017, 6:28 AM
Nomeh Uchenna Gabriel
Nomeh Uchenna Gabriel - avatar
+ 2
yeh. . I know with arrays but I want with numerous Data type in C++.
10th Sep 2017, 6:30 AM
Azam
Azam - avatar
+ 2
now Run code for negative values
10th Sep 2017, 6:31 AM
Azam
Azam - avatar
+ 1
thanks @ace
10th Sep 2017, 5:18 AM
Azam
Azam - avatar