pTutorial

New way to learn Programming

Count number of digits in C

User define C program to count the number of digits in an integers. Suppose entered number is 786 then the total number of digits are 3.

Count number of digits


#include <stdio.h>
#include <conio.h>
void main()
{
int number,count=0;
printf("Please enter a number : ");
scanf("%d",&number);
while(number!=0)
{
	count=count+1;
	number=number/10;	
}
	
	printf("Total number of digits=%d",count);
	getch();
}

Download Count number c example

Output of program

c program to count number of digits in an number

Explanation

The above program first takes a number through the scanf function and stores the number on the "number" variable that is a simple integer variable. Execute a while loop until the entered number is zero and count will be increase 1 every times. Finally print the count variable to see the result.


QUOTES OF THE DAY

A good beginning makes a good ending.

LIKE ON FACEBOOK

+1 ON GOOGLE

SHARE ON TWITTER