# How to count the number of digits of any number using C++

[803 views]

In this tutorial we will learn how can we count the number of Digits from any number using C++ program. When we input any number, that is a combination of digits. Suppose we give an input of 6574, here the number of digits is 4. To calculate the digits of any number we have three possibilities to input values.

• The Number is a +ve Number
• The Number is a -ve Number
• The Number is Zero So we will write a C++ program which satisfy the above three condition. In this program we will use if statement and while loop to satisfy all the above three condition.

## C++ Program To Count The Number Of Digits From Any Number

#include<iostream.h> #include<conio.h> void main() { int no,a=0; clrscr(); cout<<"Enter any number : "; cin>>no; if(no<0) { no=no * -1; } else if(no==0) { no=1; } while(no>0) { no=no/10; a++; } cout<<"\n No. of digits in given number is: "<<a; getch(); }

## Output

Enter any number : -650 No. of digits in given number is : 3

## Struggling to Understand Algorithm and Flowchart? Try our Notes

#### Want to Test Your Knowledge on Algorithm and Flowchart?

##### Play 2048 Game Online and Relax. 