public static int GetReversedNumber(int n)
{
int r, sum = 0, input = n;
if (n < 10) return n;
while (n != 0)
{
r = n % 10;
sum = sum * 10 + r;
n = n / 10;
}
return sum;
}
How it works:
The logic starts in the same way as splitting the numbers, but for every time a remainder is obtained, it is added up on to a sum and before adding up the remainder the sum is multiplied with a 10 so that it grows in one place in the number.
For an input 1423:
sum = 0*10 + 3 = 3
sum = 3*10 + 2 = 32
sum = 32*10 + 4 = 324
sum = 324*10 + 1 = 3241