/*
Reverse digits of an integer.
Example1: x = 123, return 321
Example2: x = -123, return -321
*/
Reverse digits of an integer.
Example1: x = 123, return 321
Example2: x = -123, return -321
*/
#include<stdio.h>
#define INT_MAX 2147483647l
#define INT_MIN -2147483648l
int reverse(int x) {
int native = x > 0 ? 1 : -1;
x = x * native;
long long result = 0;
while (x > 0){
result = result * 10 + x % 10;
if (result > INT_MAX || result * -1 < INT_MIN){
return 0;
}
x = x / 10;
}
result *= native;
return result;
}
int main(){
//1534236469
int result = reverse(1534236469);
printf("result = %d\n", result);
printf("Hello world \n");
return 0;
}