JOHNSMITH8338 JOHNSMITH8338 - 2 months ago 9
C++ Question

How to find the second to last digit of a six digit number?

For example, if the number is 431678 I need to find the 7 and 8.

To find the 8 I divide the number (with %) by 10. I don't know how to find the 7. I assume I use division possibly by 10000? How can I get my program to print 7(second to last digit)? It's obviously a simple program so I'm looking for the simple arithmetic.

Answer
const unsigned x = 431678;
std::cout << ((x / 10) % 10);