write a program to count the digit of the given number



The code for this program is as follows:

#include<iostream.h>
#include<conio.h>

void main()
{
int no,c=0;
clrscr();
cout <<"Enter any number : ";
cin>>no;
while(no>0)
{
no=no/10;
c++;
}
cout <<"\n Number of Digits in given number is: "<<c;
getch();
}

#include<iostream.h> used for input/output of data
#include<conio.h> provides several functions like clrscr(), getch() etc.
After that in main() function we have declared a variables no, c=0, temp; after that we have used clrscr(); function to clear the scree when program will run. It will clear the previous output from any program. Now we have used the cout function that shows message “Enter any number :”; and when we enter any number then this number is read by cin function and assign to no variable.
Here we have used a while loop. Here we have used the condition no>0 means loop will be continued while the value of no variable is greater than 0. Inside the loop, now we have to get the next digit so that we have used the no/10 and assign it to no. now we have incremented the value of c by one so that while loop will iterate any number of times to reach the no>0 till the c will be incremented by 1 and we get the number of digits of input.
The output is as follows:

c++ program