C Program to Find Total Number of Digit in a Given Number

« C Tutorial C Examples »

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

// Write a program in C to calculate the total
// number of digit in a given number

int main()
    int num, tim=0;
    printf("Enter any number: ");
    scanf("%d", &num);
        num = num/10;
    printf("\nTotal number of Digit = %d", tim);
    return 0;

As the above program was written under Code::Blocks IDE, therefore after successful build and run, here is the output you will also get on your output screen. 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 total of 5 digits, therefore here is the output you will get:

calculate number of digit in given number c

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

« C Tutorial C Examples »


Quick Links
Signup - Login - Give Online Test