How to calculate the number of digits using log in C

1 Answer

0 votes
#include <stdio.h>
#include <math.h>

int count_digit(int number) {
   return (int)log10(number) + 1;            
}
 
int main() {
   printf("%d", count_digit(579014));
   
   return 0;
}    



/*
run:

6

*/

 



answered Apr 6, 2025 by avibootz

Related questions

1 answer 73 views
1 answer 194 views
2 answers 323 views
1 answer 71 views
1 answer 119 views
1 answer 119 views
...