Is there an algorithm in C++ to determine the digit located on a given place value of an integer? For example, 9 would be outputted as the tens value of 196.
If none exists, is it possible to code it? If so, what are some of your ideas to do it?
Is there an algorithm in C++ to determine the digit located on a given place value of an integer? For example, 9 would be outputted as the tens value of 196.
If none exists, is it possible to code it? If so, what are some of your ideas to do it?
If you want to determine n-th digit (from the back, so second digit in 1234 is 3) in a number, you do this:
a = number%(10^n) (now your digit is in first place)
digit = a/(10^(n-1)) (now everything is stripped except your digit)
That's the algorithm
You can also convert the integer into a string, and then retrieve the particular nth placed digit of the string.