C Program to Find the Total Number of Digits in a Given Number

In this article, we will learn to create a program in C that will ask the user to enter any number (at run-time) to find and print the total number of digits present in that given number. Here is the program:

#include<stdio.h>
#include<conio.h>
int main()
{
    int num, tim=0;
    printf("Enter any number: ");
    scanf("%d", &num);
    while(num>0)
    {
        tim++;
        num = num/10;
    }
    printf("\nTotal number of Digit = %d", tim);
    getch();
    return 0;
}

As the above program was written in the Code::Blocks IDE, here is the output you will also get on your output screen after a successful build and run. This is the first snapshot of the sample run:

c program print total number of digit

Supply any number, say 24304, and press ENTER to see the output. As the number 24304 has a total of 5 digits, here is the output you will get:

calculate number of digit in given number c

Here are some of the main steps used in the above program:

C Quiz


« Previous Program Next Program »