/*
    LOOP PRACTICE - Count digits (while loop)
    -----------------------------------------
    Ask the user for a number. Use a while loop to count
    how many digits it has. (Keep dividing by 10 until 0.)
    Example: 1234 has 4 digits.
*/

#include <stdio.h>

int main(void) {
    int num;
    int count = 0;
    int n;

    printf("Enter a number: ");
    scanf("%d", &num);

    n = num;
    if (n == 0) {
        count = 1;
    } else {
        if (n < 0)
            n = -n;
        while (n > 0) {
            count++;
            n = n / 10;
        }
    }

    printf("%d has %d digit(s).\n", num, count);

    return 0;
}
