I am looking for the C program for reverse the digits like below:
If i enter:
123456
Then the result would
Here is another possibility. It is non-recursive, and perhaps a little less code. There is an example in the code comments to explain the logic.
/*
Example: input = 12345
The following table shows the value of input and x
at the end of iteration i (not in code) of while-loop.
----------------------
i | input | x
----------------------
0 12345 0
1 1234 5
2 123 54
3 12 543
4 1 5432
5 0 54321
----------------------
*/
uint32_t
reverseIntegerDigits( uint32_t input )
{
uint32_t x = 0;
while( input )
{
x = 10 * x + ( input % 10 );
input = input / 10;
}
return x;
}