COUNT THE NUMBER OF DIGITS IN GIVEN NUMBER

COUNT THE NUMBER OF DIGITS IN GIVEN NUMBER 




source code :
//wap to count the number of digits in given number  
// example no. is 542, the digits in given no. is 3
/* 542/10=54 -------1
54/10=5--------2
5/10=0-----------3
*/
#include<iostream>
using namespace std;
int main(){
      int n,count=0;
      cout<<"ENter the number : "<<endl;
      cin>>n;
      if(n==0)
      cout<<"there is only 1 digits."<<endl;
      else{
      while(n!=0)
      {
          n=n/10;
          count ++;
      }
      cout<<"The no. of digits in given number is "<<count<<endl;
      }
      return  0;

}

output : 


 

Previous
Next Post »