1、
1 / * 2 each digit positive integer order output, separated by spaces between the numbers . 3 123456 1 2. 6. 5. 4. 3 . 4 * / . 5 . 6 #include <stdio.h> . 7 int POW ( int A, int B ); . 8 . 9 int main () 10 { . 11 int n-; 12 is 13 is scanf_s ( " % D " , & n-); 14 15 // Analyzing several of a number 16 int COUNT = 0 ; . 17 int TEMP = n-; 18 is do . 19 { 20 is TEMP = TEMP / 10 ; 21 is COUNT ++ ; 22 is } the while (TEMP =! 0 ); 23 is 24 // separating each digit 25 int digit for; 26 is TEMP = n-; 27 do 28 { 29 digit for TEMP = / POW ( 10 , COUNT - . 1 ); 30 the printf ( " % D " , digit for); 31 is IF (COUNT> . 1 ) 32 { 33 printf(" "); 34 } 35 temp = temp % pow(10, count - 1); 36 count--; 37 } while (count!=0); 38 39 printf("\n"); 40 return 0; 41 } 42 int pow(int a, int b) 43 { 44 int result = 1; 45 for (int i = 0; i < b; i++) 46 { 47 result = result * a; 48 } 49 50 return result; 51 }
2, reference teacher to explain a modified version of the video
1 / * 2 each digit positive integer order output, separated by spaces between the numbers . 3 123456 1 2. 6. 5. 4. 3 . 4 * / . 5 . 6 #include <stdio.h> . 7 . 8 int main () . 9 { 10 int n-; . 11 12 is scanf_s ( " % D " , & n-); 13 is 14 int COUNT = 0 ; 15 int TEMP = n-; 16 int mask = . 1 ; . 17 do 18 is { . 19 = TEMP TEMP / 10 ; 20 is COUNT ++ ; 21 is mask mask = * 10 ; 22 is } the while (TEMP =! 0 ); 23 is 24 mask = mask / 10 ; 25 // separating each digit 26 is int digit for; 27 TEMP = n-; 28 do 29 { 30 digit for TEMP = / mask; 31 is the printf ( " % D " , digit for); 32 IF (COUNT>1) 33 { 34 printf(" "); 35 } 36 temp = temp % mask; 37 count--; 38 mask = mask / 10; 39 } while (count!=0); 40 41 printf("\n"); 42 return 0; 43 }