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:-
- Takes two integer variable.
- Take integer number from the user.
- 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.
- increase the count value to 1.
- number = number / 10 ; it is used for remove the last element from the number.
Let’s See an example of it :-
- #include<iostream> // It is a header file Library.
- using namespace std ; // we can use names for object and variable from the standard library.
- int main() // It is a function.
- {
- int num , count = 0; // takes two integer variable
- cout << "enter any interger number :"; // It takes input from the user.
- cin >> num ;
- while(num != 0)
- {
- count++;
- num = num / 10 ;
- }
- cout << "the total number of digit : " <<count;
- }
If you wants to learn more programming question then you can visit my Blog.
Comments
Post a Comment