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.
@HotaLIsa

You could create 3 integers. One for your 3 digit number, one for the first digit, like the 1, and the third integer for the value of the last two remaining digits. Assign first integer with the number. Let's say 321. Since you know it'll be 3 digits, divide the 3 digit number by 100. That would make integer 2, to be 3. Digit 3 is assigned the remaining number, as such..
integer three=integer one-(integer two*100). Since integer two right now equals 3, you would be subtracting 3*100 or 300, from the initial number, which was 321, leaving 21 to be assigned to integer three
Last edited on
Just convert the int to a string and use the subscript operator.
1
2
3
int num = 123;
int firstDigit = num/100;
int lastTwoDigits = num%100;

Topic archived. No new replies allowed.