How do I extract a single digit from a 3 digit whole number?

This isn't a homework question, I'm just curious. If I had a program that calculated a 3 digit number, say 123, how can I get just the "1"? I'm trying to print a message at the end that says "(The first digit) tells you...and (the last two digits) tell you..." But I'm not sure HOW to save or get that single digit. Any ideas? Is the a simpler way to do this other than using an array?Thanks.
Make use of integer division.

1
2
3
4
5
6
7
8
9
10
11
#include <iostream>
using std::cout;

int main ( )
{
	int num = 123;
	int firstDigit = num / 100;

	cout << "Number: " << num << "\n";
	cout << "First digit: " << firstDigit << "\n";
}
Last edited on
Topic archived. No new replies allowed.