#include<iostream.h>
void main()
{
int num,c=0;
char repeat='y';
while(repeat=='y')
{
cout<<" Enter a number : ";
cin>>num;
c=0;
while(num<0)
{
num = num / 10;
c++;
}
c=0;
while(num>0)
{
num = num / 10;
c++;
}
cout<<" Number of digits = "<<c<<endl;
cout<<" Do you want another attempt ? (y/n) ";
cin>>repeat;
}
}
Output:
Enter a number : 56237
Number of digits = 5
Do you want another attempt ? (y/n) y
Enter a number : 981
Number of digits = 3
Do you want another attempt ? (y/n) n
Press any key to continue |