How do I count the number of digits in any integer in C++ using only loops?

         Count the number of digits in any integer in C++ using       loops :- 

  C++ was developed by bjarne stroustrup and it is used to create high performance application.

Steps:-

  1. Takes two integer variable.
  2. Take integer number from the user.
  3. we are using while loop. in while loop we are passed number doesn’t equal to 0. the number means we taken from the user.
  4. increase the count value to 1.
  5. number = number / 10 ; it is used for remove the last element from the number.

Let’s See an example of it :-

  1. #include<iostream> // It is a header file Library. 
  2. using namespace std ; // we can use names for object and variable from the standard library. 
  3. int main() // It is a function. 
  4. { 
  5. int num , count = 0; // takes two integer variable 
  6. cout << "enter any interger number :"; // It takes input from the user. 
  7. cin >> num ; 
  8. while(num != 0)  
  9. { 
  10. count++; 
  11. num = num / 10 ; 
  12. } 
  13. cout << "the total number of digit : " <<count; 
  14. } 

If you wants to learn more programming question then you can visit my Blog.

Comments

Popular posts from this blog

proassignment help backlink data index 41

programming shark backink data index 31

Programming shark backlink data index 67