Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static class Reverse
- {
- public static int ReverseInt(int x)
- {
- int[] a = new int[10];
- int temp = x, b = 0, c = 1, d = 0, f = 0;
- bool n = false;
- if (x < 0)
- {
- x = x - x - x;
- n = true;
- }
- else if (x == int.MaxValue)
- {
- return 0;
- }
- while (x > 0)
- {
- a[b] = x % 10;
- b++;
- x = x / 10;
- d++;
- }
- d--;
- while (true)
- {
- if (d == -1)
- break;
- f += a[d] * c;
- c *= 10;
- d--;
- }
- if (n == true)
- {
- f = f - f - f;
- if (int.MinValue < f && f > 0)
- {
- return 0;
- }
- }
- d++;
- if (f < temp && temp > 0 && a[d] != 0 && b == 10)
- return 0;
- return f;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement