Dremendo Tag Line

Input a number and count the number of digits in it using while loop in C

while Loop - Question 11

In this question, we will see how to input a number and count the number of digits in it in C programming using while loop. To know more about while loop click on the while loop lesson.

Q11) Write a program in C to input a number and count the number of digits in it using while loop.

Program

#include <stdio.h>
#include <conio.h>

int main()
{
    int n,c=0;

    printf("Enter any number ");
    scanf("%d",&n);

    while(n>0)
    {
        c=c+1;
        n=n/10;
    }
    printf("Total Number of Digits = %d",c);
    return 0;
}

Output

Enter any number 42638
Total Number of Digits = 5
video-poster