I want to create a function which will a number and the position of the digit that I want to retrieve,
int getDigit(int value, int positionFromLeft)
Say, getDigit(534, 2) will return 3.
What could be the easiest / efficient way to write this function?
All these string-based solutions scare me… Really guys? :-/
Note that passing an out-of-bounds value for
positionFromLeftwon’t return any sensical value as-is.