// num is the number in question
// place is the name for the digit you want, 1, 10, 100, etc. A well-formed place will be an integral power of 10, but let's not count on that
int get_digit (int num, int place)
{
if (place < 0)
// choke and die with nasty error
else if ( place < 10) return num% 10;
else return get_digit((int) num / 10, (int) place / 10);
}
// if you can guarantee that the number requested is 'well-formed'...
int get_digit(int num, int place)
{
return ((int) num / place) % 10;
}
// maybe you're expecting places named 0, 1, 2,... instead of 1, 10, 100...
int get_digit(int num, int place)
{
return ((int) num / pow(10, place)) % 10;
}