In this program, the user is ask to enter the number, then the number of digits the given number have will be displayed on console.
#include<iostream>
using namespace std;
int main()
{
int num, digit=0;
//;
cout<<"Enter a number: ";
cin>>num;
while(num!=0)
{
digit++;
num = num / 10;
}
cout<<"No. of digits = " << digit;
return 0;
}
Enter a number: 42513
No. of digits = 5
Enter a number: 47
No. of digits = 2