Calculates the number of times a number appears in a value range and the number of times a value range appears.
Calculates the number of times a number 9 appears in a numerical range.
1. Program Implementation
2. Function Testing
3 program optimization
4. Add debugging code
··············
1. Program Implementation
Vim 9.c
Gcc 9.c
./A. out
The image is too large. Change the number of columns to 10.
2. Function Testing
Test whether the 9 value in a number can be accurately determined.
Modify:
......
./A. out
Display num: 9 in 9938 and 9939. There are. | 9938 9939 From 9938 to 9939 have num 9 is: 5 |
3 program optimization
Learn a piece of code from the experts and make a modification record.
While (jj)
{ If (j = ii % 10) K ++; // Ii = (ii-ii % 10)/10; // If (ii <jj) // Jj = 0; Ii = ii/10; If (ii = ii/10) Jj = 0; } |
4. Add debugging code
Add the debugging code and modify the code as follows: (the original Lines 18 and 51; add line "well)
# If t Printf ("Display num: % d in % d and % d. \ n \ tThere are. \ n \ t |", j, min, max ); # Endif |
# If t Printf ("% 6d", I ); # Endif |
Compile:
Gcc 9.c-Dt-o 1 |
Gcc 9.c-Ut-o 2 |
./1
Display num: 9 in 9938 and 9939. There are. | 9938 9939 From 9938 to 9939 have num 9 is: 5 |
./2
From 9938 to 9939 have num 9 is: 5 |