JOHNSMITH8338
JOHNSMITH8338

Reputation: 95

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.

Upvotes: 1

Views: 9828

Answers (1)

timrau
timrau

Reputation: 23058

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

Upvotes: 7

Related Questions