How do I get what the digits of a number are in C++ without converting it to strings or character arrays?
Those solutions are all recursive or iterative. Might a more direct approach be a little more efficient?
Left-to-right:
int getDigit(int from, int index)
{
return (from / (int)pow(10, floor(log10(from)) - index)) % 10;
}
Right-to-left:
int getDigit(int from, int index)
{
return (from / pow(10, index)) % 10;
}