Write a C Program to Count the Number of Digits in a Number

In this tutorial learn how you can write a c program to count the number of digits in a number.

We are using the while loop and if statement for this tutorial.

C programming is a powerful general-purpose programming language. It can be used to develop software like operating systems, databases, compilers, etc.


write c program to count number of digits in a number


Write a Program to Count the Number of Digits in a Number

Here is the code to count the number of digits in a number in C programming.

#include <stdio.h> //WAP to count the number of digits in a number.
int main()
{
    int num, counter = 0;
    printf("Enter any numbr of your choices:");
    scanf("%d", &num);
    while (num != 0)
    {
        num = num / 10;
        counter++;
    }
    printf("The number of digits are %d.", counter);

    return 0;
}

Test Live At Jdoodle



Conclusion

This is how you can count the number of digits in a number in c programming. Comment below if you like our tutorial.

0 Comments