Use the loop to solve ~ ~
M divided by 10, and then counted with a variable count, plus 1 per loop, until the number is less than 10 after the number, Count plus 1.
Example: Integer m=4325,
First: 4325/10=432,m results are not for 0,cout=1;
First: 432/10=43,m results are not for 0,cout=2;
Third time: 43/10=4,m result is not 0,count=3;
The fourth time: M is 4, the result is not 0,count=4; but M/10 is 0, and the loop is over.
As for each digit that holds an integer, we can use the most conventional method, using modulo (%) and division (/) to obtain each digit ~ ~ ~
You can also take advantage of the above cycle, because each time divided by 10 after the number, then modulo, you can get the number at the end of the digit,
- <span style=" FONT-SIZE:18PX; " > #include " iostream " &NBSP;&NBSP;
- using namespace std;
- int Main ()
- {
- int n,m=0,j=0;
- int A[10];
- cin>>n;
- while (n!=0)
- {
- int x=n%10;
- A[j]=x; //This is to save the number on each
- j + +;
- N=N/10; //Each time divided by 10, the result is not 0, then M can add 1.
- m++;
- }
- cout<<m<<endl; //number of output bits
- for Span style= "margin:0px; padding:0px; Border:currentcolor "> (int i=0;i<m;i++ )
- {
- cout<<a[i]<< ' ' ; //flashback output per digit
- }
- return 0;
- }</span>
How to calculate the number of digits of an integer & Save the numbers on each one