Skip to content

Commit f2ca754

Browse files
committed
Create int_reverse.c
1 parent 14dfc2d commit f2ca754

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

Diff for: int_reverse.c

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
int reverse(int x)
2+
{
3+
long int r = 0;
4+
for (;x != 0;)
5+
{
6+
r = r * 10 + (long)(x) % 10;
7+
x /= 10;
8+
}
9+
int i_max = (int)(~(uint)(0) >> (uint)(1));
10+
int i_min = -i_max - 1;
11+
if (r > i_max || r < i_min)
12+
{
13+
return 0;
14+
}
15+
return (int)(r);
16+
}

0 commit comments

Comments
 (0)