n!=0
will be true in first iteration. The codes inside while loop will be executed. After first iteration, value of n will be 3452 and count will be 1. Similarly, in second iteration n will be equal to 345 and count will be equal to 2. This process goes on and after fourth iteration, n will be equal to 3 and count will be equal to 4. Then, in next iteration n will be equal to 0 and count will be equal to 5 and program will be terminated as
n!=0
becomes false. Source Code:-
#include<iostream.h>
#include<conio.h>
void main()
{ clrscr();
long int num1,count=0;
cout<<"count number of digits in a number by-Tarun Rawat\n\n";
cout<<"Enter number to count it's Digit : ";
cin>>num1;
while(num1!=0)
{num1=num1/10;
count++;
}
cout<<"Number of Digit is : "<<count;
getch();
}
No comments:
Post a Comment