#include <iostream>

int first_digit( unsigned int number )
{
    std::cout << "number: " << number << '\n' ;

    if( number < 10 ) // the number consists of a single digit
    {
        std::cout << "there is just one digit, return it\n" ;
        return number ; // just return that digit
    }

    // the number consists of two or more digits
    // number/10 gives the number with the last (right-most) digit removed

    return first_digit( number/10 ) ; // call recursively with one less digit

    // each time through the recursion, we reduce the number of digits by one.
    // Eventually, when there is just one digit left,
    // that is the first (left-most) digit and we return that
}

int main()
{
    std::cout << first_digit(12345678) << '\n' ;
}
