Reverse a Number
excerpt: This covers the basic building blocks such as Modulo Operator, Reducing in Input by Integer Division and Place Value tags: modulo-operator reducing-input-value place-value
Write a function to reverse a given number.
- Extract the last number by using Modulo operator.
- Take the digit’s position in the result into account (10, 100, 1000 etc). This is the Place Value in action.
- Add it to reversed digit with extracted digit from the input number.
Recursive Implementation
|
|
Iterative Implementation
|
|
Building Blocks
- Modulo Operator to Extract Digit
- Reducing in Input by Integer Division
- Place Value