Count Digits in C
Level 3100 keystrokes
Counts the number of digits in an integer by repeatedly dividing by 10.
C code
// A 5-digit number1int num = 12345;// Number of digits found so far2int count = 0;// Repeat until every digit has been removed3while (num > 0) { // One more digit4 count++; // Integer division drops the last digit: 12345 → 1234 → … → 05 num /= 10;6}// The loop ran 5 times: Digits: 5 (with num = 0 it would print 0)7printf("Digits: %d", count);Output
Digits: 5
Practice typing this code. Results are not recorded in the rankings.
Symbols in this code
The symbols you type in this C code and how often they appear.
;× 5=× 3"× 2(× 2)× 2+× 2,× 1:× 1{× 1}× 1