I have a number like this: int num = 36729; and I want to get the number of digits that compose the number (in this case 5 digits).
int num = 36729;
How can I do this?>
For any input other than 0, compute the base-10 logarithm of the absolute value of the input, take the floor of that result and add 1:
int dig; ... if (input == 0) dig = 1; else dig = (int) floor(log10(abs((double) input))) + 1;
0 is a special case and has to be handled separately.