Count The Digits In An Integer Number | C Programming Example

preview_player
Показать описание
Рекомендации по теме
Комментарии
Автор

Do while loop makes the algorithm perfect in case if the input is : 0.

justcurious
Автор

How about this, I think its simpler and maybe even faster
char buffer[32];
int num_digits;
num_digitss = snprintf)buffer, sizeof(buffer), "%d", number);
if(number<0) num_digits--; // don't count the minus sign if there is one

erbenton
Автор

Or, you can just convert the integer to a character string and then get the string length.

SlideRSB
join shbcf.ru