Reversing Digits of an Integer Algorithm O Level Python
Reversing digits means changing the digits order backward. For Example
Input - 8672
Result - 2768 (Each digit places in reversed order)
To do this, divided the number by 10 and get the remainder like this.
You can get remainder by mod() also-
n = 8672 mod (10) = 2
Now remove 2 from the original integer number. So you get next number 867 (number to be reversed), again
n = 867 mod (10) = 7
Successively, find out the remainders until the dividend is less than 10. Now place the digits of remainders in reverse order.
- Begin
- Get any integer number to be reversed
- To do this, divided the number by 10 and get the remainder and write it in reverse order
- You can get remainder by mod() function by extracting the right most digit of the number
- find out the remainders until the dividend is less than 10. Now place the digits of remainders in reverse order
- Stop
0 Comments