C number of digits in integer

To find the number of digits in an integer in C, you can use a loop to repeatedly divide the integer by 10 until it becomes 0. Each time you divide by 10, you can increment a counter variable to keep track of the number of digits. Here's an example code snippet:

#include <stdio.h>

int main() {
    int num, count = 0;

    printf("Enter an integer: ");
    scanf("%d", &num);

    while (num != 0) {
        num /= 10;
        ++count;
    }

    printf("Number of digits: %d\n", count);

    return 0;
}

This code prompts the user to enter an integer, then uses a while loop to divide the number by 10 until it becomes 0. Each time the loop runs, the count variable is incremented to keep track of the number of digits. Finally, the code prints the count, which represents the number of digits in the integer.