( CIP) /. :, ( ) ISBN TP CIP ( 2005) : : : : * : : 174 ( A ) : : ( 023) : ( 023)
|
|
|
- 鸭押盎 平
- 9 years ago
- Views:
Transcription
1
2 ( CIP) /. :, ( ) ISBN TP CIP ( 2005) : : : : * : : 174 ( A ) : : ( 023) : ( 023) : http: / /www. cqup. com. cn : fxk@cqup. com. cn ( ) * : /16 :24 : : ISBN :30. 00,,,
3 ( )
4 ,,,,,,,, 21,, ;, ;,, 1
5 2, : 1.,,, 2., ; ;, 3.,,,,, 4.,,,,,, :, ;, ;, ;,,,,,,
6 ,, C, C,,,, :,,, C 1
7 2 ; C,, C ; C,, C ; C C + + Java C# C, C, C 3 : 1 2 C, C C, C 3 C, C C, C ASCII,, :, 1 9 ;, 4 ;, 6 7 ;, 2 3 ;, 5 8 ;,,,, :, xiongz@ cqu. edu. cn, xiongz@ cqcnc. com
8 ( 1) ( 1) ( 2) 1. 2 ( 3) ( 4) ( 4) ( 7) ( 8) 1 ( 12) 2. 1 C ( 13) 2. 2 C ( 15) C ( 15) C ( 17) 2. 3 C ( 17) C ( 17) C ( 20) 2. 4 ( 25)
9 ( 25) ( 26) ( 27) ( 28) ( 30) sizeof ( 31) 2. 5 ( 32) ( 32) ( 33) ( 33) 2. 6 C ( 34) C ( 34) C 7 ( 36) C ( 38) ( 38) 2. 7 ( 45) 2 ( 48) 3. 1 C ( 52) 3. 2 C ( 53) ( 53) ( 54) 3. 3 ( 57) ( 57) C ( 58) 3. 4 ( 73) ( 73) while ( 74) do while ( 75) for ( 77) ( 80) ( 81) ( 84) 3. 5 ( 85) goto ( 85) break ( 86) continue ( 88)
10 3. 6 ( 90) ( 90) ( 97) 3. 7 ( 105) ( 105) ( 106) ( 107) ( 108) ( 109) ( 109) ( 110) 3 ( 111) 4. 1 ( 116) ( 116) C ( 117) 4. 2 ( 118) ( 118) ( 121) ( 123) ( 126) 4. 3 ( 128) 4. 4 ( 133) 4. 5 ( 137) ( 138) ( 140) ( 144) 4. 6 C ( 147) ( 147) ( 148) ( 149) ( 150) ( 151) ( 156) 4 ( 157) 3
11 5. 1 ( 165) ( 165) ( 167) 5. 2 ( 174) ( 174) ( 176) 5. 3 ( 177) ( 178) ( 180) 5. 4 ( 181) 5. 5 ( 182) 5 ( 183) ( 188) ( 188) ( 190) ( 196) ( 197) ( 200) ( 207) ( 211) ( 219) 6. 2 ( 224) ( 224) ( 225) ( 227) ( 234) ( 237) 6. 3 ( 241) ( 241) ( 242) typedef ( 246) ( 247) ( 249)
12 ( 251) 6. 4 ( 254) ( 254) ( 255) 6. 5 ( 259) ( 259) ( 260) 6 ( 262) 7. 1 ( 265) ( 265) ( 266) 7. 2 ( 268) ( 268) ( 269) ( 270) ( 271) ( 271) ( 272) ( 273) 7. 3 ( 273) 7. 4 ( 277) ( 277) ( 279) 7 ( 280) ( 282) ( 282) ( 282) ( 284) 8. 2 ( 285) ( 285) ( 287) 8. 3 ( 287) ( 287)
13 ( 294) ( 296) ( 297) 8. 4 ( 301) ( 301) ( 303) 8. 5 ( 304) ferror ( 304) clearerr ( 305) 8 ( 305) ( 310) C ( 310) ( 314) ( 327) ( 332) 9. 2 ( 339) ( 339) ( 342) ( 344) ( 346) ( 348) ( 350) 9. 3 ( 352) ( 352) ( 354) 9. 4 ( 356) C ( 356) C ( 357) C ( 368) 9 ( 372)
14 ,,,,,,, 1 ),,,,,,
15 ,, :, ;, 2 ) 2,,,,,,,,,,,,,, 3 ), Fortran C,, ; C + + Smalltalk,,, :,,,, ,,,
16 2 :,,,,, ,,,, :, ( Nikiklaus Wirth) : = +
17 , 3,, ;, ;,, ( ),,,,, 2 :,, ( ),, 3, ( ),, ; ;,, C,, C ;,, ),,,,
18 ,, : 1 ; 2 : 2 a b; 3 a > b, a b ;, b a ; 4 2 ) 5,, : sinx = x - x 3 3! + x5 5! - x 7 7! + x9 9! -,, (, 10-5 ),,,,, 5,, : 1 ; 2 0 n( n 0 ) ; 3 n + 1 n( n 1) ; 4 3 ; 5,,,, :,,, 0,, ; 5
19 ,,, 3 ) 6,,, 3, 3, 3 : ( ), :,,, 1. 2 ( ),, 1. 2, : ( ) 2, , :,,
20 ,,, ( ), A3 0 B A3 0 B,,,, 3 : N S ( ) 1 ), ( 1. 5 ), ( ),, ) N S N S Nassi Shneiderman2,,, N S N S
21 3 ) 8 N S,,,,,,,, 3 : ( 1) S1 S2 ( 2) If( ) then 1 Else 2 ( 3) Switch( ) 1: S1 2: S2 n: Sn ( 4) While( ) ( ) 5 ) Do ( ) While( ) 3,, ,,
22 1. 1 r h ( 1) :,, ( 2) : SF - 01 r h 3. 14* r* r* h / a b,, 2 ( 1) :, a b a* b < 0 ( 2) : SF a b If( a* b < 0 ) then Else S S ( a* b) 1 / 2 S ( a + b) / ( 1) : : ; 400 : 2, ( 2) : SF - 03 year If( ( year MOD 400 = 0) ( year MOD 4 = 0) ( year MOD 100 0) ) then Else year year : MOD ( ) x y z, ( 1) : x y x; y z, y > z y ; y < z z x ( 2) : SF
23 10 x y z 3 If( x < y) then x y If( y > z) then Else y If( x > z) then Else 1. 5 z x ( 1) : ( 1 7 ), ( 2) : SF - 05 w Switch ( w) w = 1: " Monday" w = 2: " Tuesday" w = 3: " Wednesday" w = 4: " Thursday" w = 5: : " Friday" w = 6: " Saturday" w = 7: " Sunday" 1. 6 n, n! ( 1) :, 1 : 1 n ; ( 2) : SF - 06 n k < - 0 p < - 1 While( k < n) k < - k + 1 p = p* k
24 n! p 1. 7,, ( 1) :, 2 : ; :, ; ; ; : 10 ( 10 ), ; ;, ( 2) : SF - 07 n s < - 0( 0) Do m < - n MOD 10 s < - s* 10 + m n < - n /10( n 10 n) While( n > 0 ) s 1. 8 : 5, 4, ,? ( 1) : x, y, z : x + y + z = x + 3y z = 100 x : 1 19 y : 1 33 z : z = x - y ( 2) : SF - 08
25 x < - 1 y < - 1 While( x < 19) While( y < 33) z = x - y If( 5* x + 3* y + z /3 = 100) then x y z y < - y + 1 x < - x , ; a 1 x + b 1 y = c 1 a 2 x + b 2 y = c , A( x 1, x 2,, x n ) n R n, A O( 0, 0,, 0), n 1. 5 A m n, , 36, 4, 3, 2 1,? 1. 7, : , : 1 ) 1000, ; 2 ) 2000, ; 3 ) 3000, ; 4 ) 5000, ; 1. 9 :, ( - 1 ),, 9
26 C 2. 1 C 13 C,,, ( ), C C, Martin Richards BCPL( Basic Combined Programming Language) 20 70, Ken Thompsom BCPL, B ( BCPL ) PDP-7 UNIX, PDP-11 UNIX, Dennis. M. Ritchie Vrian. W. Kernighan B, 1972 C ( BCPL ), 20 80, ( ANSI) C C, ANSI C ( 1989 ) C, C,,, C : C, C 32, 9
27 14,, C C, ( bit),, C, C, C,,, C C C : ( ),, C C, 34, + - * / ( &&) ( ) (! ), ( &) ( ) ( ) ( ^) ( < <, > > ), = - = * = / = C, C C, C, ( UNIX MS-DOS Windows ) C,,, C,, C Microsoft C Turbo C Borland C,, C ( ), C 2. 2 C C,
28 C C 2 C , / * * / / * main * / { float ave, x, y, z; /* * / scanf( % f, % f, % f, &x, &y, &z) ; /* scanf * / ave = ( x + y + z) /3; / * * / printf( % f, ave) ; / * printf * /, main, C, main; { 4 C ; scanf C, ; printf C, / * * / 2. 2, : main, myputc, myputc,,,, / * ex2-2. cpp * / #define SIZE 80 / * ( SIZE) ( SIZE) * / { void myputc( char ch) ; / * myputc * / char str[ SIZE] ; / * ( str) * / int j; / * ( j) * / gets( str) ; / * gets * / for( j = 0 ; str[ j]! = \0 ; j + + ) myputc( str[ j] ) ; / * myputc* / void myputc( char ch) / * myputc* / { char cc; cc = ( ch > = a && ch < = z )? ch + A - a : ch; putchar( cc) ; 15
29 16 main myputc, myputc C,,, C : : C ; C : ( ) C main( ) : C main( ),, ( include ), ;,, ;, : C,, \ C, C /, / ( : scanf( ) printf( ) getchar( ) putchar( ) ) / * * /,, C : C, C C,, ( ; ) C,, C ( ), C, C C,,, C : : (, ) : void myputc( char ch) : { ;
30 C ; C 3 : ( main( ) ) C,,, 2. 3 C C,,,,,,,, 17 1 ) C, C 91 : a, b, c,, z A, B, C,, Z 0, 1, 2, 3,, 9 _ ( ) * & %! < >., ; : /? { [ ] ^ : C 32 ( ),, C, C ( ) :
31 auto break case char const continue default do double else enum extern float for goto if int long register return short signed sizeof static struct switch typedef union unsigned void volatile while 18, C,, : define undef include ifdef ifndef endif line error elif pragma C,, ;, :, ( Turbo C 1 32 ) C,,, C, total TO- TAL ToTaL total C, ( ),, name / xm( ) sex/ xb( ) age /nl( ) salary /gz( ) : a b1 file_name _buf : 5 c int up. to file name. 2 ) C, C,,, C C
32 C C, 2. 1,,,, 3 ), C,, 2. 1 C, C 3 :,,,,, 2. 2 SIZE,,, C,,,, :, : [ ] [, 2 ] ; ;, float. radius, length, area ; : : ( int float char ) ; : 19
33 C 1 ) 20 ( 1) C, 3 : : 0 888, - 123, 0, : 0, 0777, : 0x, 0x123, 0xff ( 2) C : 4, int short long unsigned int C,,,, 2. 1 IBM-PC 2. 1 IBM-PC ( 16 ) int short int long int l unsigned int u char A : l L ; u : ; : int a, b; / * a, b * / long x, y; / * x, y * / unsigned c, d; / * c, d * / 2. 3 { int x;
34 C long y; unsigend z; x = 888; y = 0x7ffa; z = 65535; printf( % d, % ld, % u \ n, x, y, z) ; : 888, 32762, ) ( 1), C,, : : 3 : :, e E 3 : < > E( e) < > : : : : 1. 23e ; e E E - 4 ; e3 2. 1e3. 5. e3 e 4, , 7 ( 2) C, float double 6 7, 4, 8, , 8 : float double ; ; : float x, y; / * x, y * / 2. 4 double z; / * z * / { 21
35 float x1, x2; double y1, y2; x1 = ; x2 = ; y1 = ; y2 = ; printf( % f, % lf\ n, x1 + x2, y1 + y2) ; : , ,,, 3 ) 22 ( 1) C 2 :, a? A \,, ( \ ) ASCII ( ) ( ), : \ r \ n \ 123 \ x C 2. 2 C \0 NULL \ b \ n \r \ f \ t \ \ \ \ \0oo o \xhh h 1, ASCII,
36 C, ASCII ( 2) 1, 1 : char ; : char ch; / * ch * / : C, 2. 5 { int a; char b; a = 1; b = A ; printf( % c \n, b + a) ; : B ( 3) C,,, : Hello, World! a 1,, : abcd \ t123 \ n \ \ \ , : abcdefg abcdefg : + 1, ASCII, NULL, NULL ASCII 0, \ 0 CHINA : 23 C H I N A \ : a,, ; 1
37 , ( a \0 ) 2 4 ) 24 C,, ( ), : #define : #define PI #define EOF - 1 C,,, : ;,,, ; 5 ) C,, : [ ] [ = ] [, 2 [ = 2 ] ] ; : float radius = 2. 5, length = 6. 5, area ; int a = 3, b = 5; char c = a ;, c a ASCII 2. 5 : { int a = 1; char b = A ; printf( % c \n, b + a) ;
38 C , ( ),,,,,,,, C, C : ( + - * / % ) ; ( > > = < < = = =! = ) ; ( &&! ) ; ( = ) ; ( & ^ < < > > ) ; (? : ) ; (, ) ; ( * &) ; ( sizeof) ; ; 1 (. - > ) ; 12 ( [ ] ) ; 13 ( ) C C,,,,,, 25
39 C 15, ( ) [ ] - >. 2! * & sizeof 3 * / % < < > > 6 < < = > > = 7 = =! = 8 & 9 ^ && 12 13?: 14 = + = - = * = / = % = & = ^= = > > = < < = 15,,,, C,, 5 + x - 1, x + -,, x +, 5 + x, -, x = y = 5, y =,, y =, = x C :, + -
40 C, 5 : + - * / %, :, : 7 /5 = 1, - 7 /5 = - 1,, : 7% 5 = 2, - 7 % 5 = - 2, 7% - 5 = 2 C C, : a* b / c a, a + b % 6 :, ( ) * / % =, : x = 10 : 10 x ; y = x + 1 : x + 1, y ( ) : = : : a = 3 b = a c = b = a = 3 :,, ( ) C, : a = ( b = 5 ), b = 5, 5 a = ( b = 5) a = 5, a 5, { int m, n, k; m = ( n = 4) + ( k = 10-7) ;
41 printf( m = % d \n, m) ; : m = 7,,, : j, j = 5. 5 j 5; x, x = 5 x ;, 8 : num float, 2. 5, num = ( int) num, num? ) C, =,, : = : a X = b ( X + - * / % ) : = ( ) a = a X b : x + = 3 /* x = x + 3* / y* = x + 6 /* y = y* ( x + 6), y = y* x + 6 * / x % = y - 5 /* x = y% ( y - 5) * /,, C,, : + = - = * = / = % = < < = > > = & = ^= = 10, 5 : 2. 7 { + = - = * = / = % =
42 C int a = 3, b = 9, c = - 7; a + = b; c + = b; b + = ( a + c) ; printf( a = % d, b = % d, c = % d \ n, a, b, c) ; a + = b = c; printf( a = % d, b = % d, c = % d \ n, a, b, c) ; a = b = c; printf( a = % d, b = % d, c = % d \ n, a, b, c) ; : a = 12, b = 23, c = 2 2 ) a = 14, b = 2, c = 2 a = 2, b = 2, c = ,, 2 : ( , + + i - - i), ( , i + + i { int j = 10, k; printf( j = % d \ t, j) ; printf( j + + = % d \ n, j + + ) ; printf( j = % d \ t, j) ; printf( + + j = % d \ n, + + j) ; : j = 10 j + + = 10 j = j = 12 C, : - ), : i k, i = 3, 29
43 i = 3 k = ( i + + ) + ( i ++ ) + ( i + + ) k 9 i ++ : i, i 1 k = = 9 i = 3 k = ( + + i) + ( ++ i) + ( + + i) k i: 1, i 3 i 1, i 6 k = = 18 30, ( ), i j, ( i + + ) + j : C,,, ( i + + ) + ( i + + ) + ( i + + ), : { int m, n, i = 3, j = 3; m = i i i + + ; /* m < * / n = + + j + ( + + j) + ( + + j) ; /* n < * / printf( % d \n, m) ; /* : 9 * / printf( % d \n, n) ; /* : 18 * / { int i = 3, j = 3; printf( % d \n, i i i + + ) ; / * : * / printf( % d \n, + + j + ( + + j) + ( + + j) ) ; / * : * / C :, :
44 C 1, 2,, n, C, : int i, j; i = 3; j = ( + + i, i + +, i + +, + + i) ; i 7, j 7 { x = 1; y = ( 1, 2, 3, 4) ; z = ( z = 2, z* 5, z + 3 ) ; : x 1, y 4, z 5 a * a = 3 * 5, a * 4 = 60: a = 3 * 5, a = 15; 4 = 60, = 60 ( a = 3 * 5, a * 4), a + 5 = 20 : a = 3 * 5, a = 15; a * 4 = 60; a + 5 = 20, = 20 C,,,,, for, 2. 9 { int x, y, z; x = 1, 2, 3, 4; y = ( 1, 2, 3, 4) ; z = ( z = 2, z* 5, z + 3) ; printf( x = % d, y = % d, z = % d \ n, x, y, z) ; : x = 1, y = 4, z = sizeof sizeof C,, x, sizeof( x) sizeof( int) 2 sizeof,,, sizeof( double), sizeof( ) C, sizeof 2. 10
45 { printf( int: % d \ n, sizeof( int) ) ; printf( short: % d \ n, sizeof( short) ) ; printf( long: % d \ n, sizeof( long) ) ; printf( unsigned: % d \n, sizeof( unsigned) ) ; printf( unsigned short: % d \ n, sizeof( unsigned short) ) ; printf( unsigned long: % d \n, sizeof( unsigned long) ) ; printf( char: % d \ n, sizeof( char) ) ; printf( unsigned char: % d \ n, sizeof( unsigned char) ) ; printf( float: % d \n, sizeof( float) ) ; printf( double: % d \n, sizeof( double) ) ; C,,, C, : Char < int < unsigned < long < float < double char short, int ; float, double ;, { int a, b, c, d, e; float f;
46 C a = 3; b = 5; c = 2; d = a + + ; printf( a = % d, d = % d \n, a, d) ; a = 3; e = + + a; printf( a = % d, e = % d \ n, a, e) ; f = b / c; e = b% c; printf( f = % f, e = % d \ n, f, e) ; : a = 4, d = 3 a = 4, e = 4 f = , e = 1, C : , ( ), :,, { char c = a ; int j = 3, k; float x = 5. 0; k = ( x* j) + ( c + j) ; printf( % d, % f \n, k, ( x* j) + ( c + j) ) ; : 115,
47 C, ( ) : ( ) < > :, :, { int k = 5, n, m; float x = 1. 2; m = ( int) x* k; n = ( int) ( x* k) ; printf( x = % f, m = % d, n = % d \n, x, m, n) ; : x = 1. 2, m = 5, n = C C, 2 : C 5 1 ) C, C,, ;, : ; :
48 C x = y + z; / * ( ) * / y + z; / *,, * / i + + ; / * 1, i 1* / 3 : : : y = x + 1; ; = ; ; : ( ) ;,, : printf( Hello, World! \ n ) ;, ; ( ), : while( getchar( )! ; = \r ) : 35 2 ), C 9, 3 : : if switch : do while while for : break goto continue return 3 ) C {,, : { x = y + z; a = b + c; printf( % d% d, x, a) ; ;,
49 ,, : { char ch; ch = getchar( ) ; putchar( ch) ; C 7 36,,, C,,,, ( Nikiklaus Wirth) : + =,,,, ,,,,, ( ), 3 :, ;, ;,
50 C,,,, : ( 1),,,,,, ( ) ( 2),,, ;,,,,, ( 3),,, ( 4),,,,, ( 5),,,, : ;, ;,, ;, ; ( 6),, ;, 37
51 ,,,, ( 7),,, : ; ;, ; ; ; C 38, C, C,, Turbo C Turbo C ( 2. 4 ) : : DOS : C: \ TC > TC < CR > Windows : : < F3 > < F10 > File Load : < F10 > File New : C : < F2 > < F10 > File Save < CR > < CR > : < F9 > Compile /MakeEXEfile < CR > < F6 >, : < Ctrl - F9 > Run Run : < Alt - F5 > Run User Screen 2. 4 Turbo C : < Alt - X > < F10 > File Quit C S : Turbo C + + IDE
52 C ,, C, I / O I / O stdio. h, I / O, : #include stdio. h 4 : printf scanf getchar poutchar 1 ) printf printf, : printf(, ) ; : ( ) : 3,, %, : % [ ] [ ] [ ] [ * ] : :, printf 39 d o x u f e g c s ( ) ( O) ( Ox) % f% e
53 40 :, % 5d 5 m. n, m, 1, n, % 5. 2f 5, 2,, 0,, 0, printf( % 05d \ n, 88 ) ; : :, ;, : l( long), ; h ( short), * : * { int i = 5, j = 6; printf( % d, % 0 * d \ n, i, i, j) ; : 5, { char c; int a = 88 ; float b = ; c = b ; printf( % d, % 04d, % - 04d, % x, % c \n, a, a, a, a, a) ; printf( % c, % d \ n, c, c) ; printf( % f, % 6. 3f \n, b, b) ; printf( % s \ n, abcdefghijk ) ; printf( % s\ n, abcdefghijk ) ; : 88, 0088, 88, 58, X
54 C b, , abcdefghijk abcd 7 a, % 04 d 4, a 88 0 % - 04d 4,, a 88 % x a, % c a, a 88, ASCII 88 X 8 c, % d c, b ASCII 9 b, % 6. 3d b, 3, b , 2, 0 11 % s\ n abcdefghijk, 4, { printf( 10 : 60 = > 8 : % o \ n, 60) ; / * * / printf( 8 : 074 = > 10 : % d \ n, 074 ) ; / * * / printf( : % d \ n, 622) ; /* 10 * / printf( : % d \ n, - 622) ; /* 10 * / printf( 10 : 116 = > 16 : % x \n, 116) ; / * * / printf( 16 : 0X74 = > 10 : % d \ n, 0X74) ; / * 16 0x * / : 10 : 60 = > 8 : 74 8 : 074 = > 10 : 60 : 622 : : 116 = > 16 : : 0X74 = > 10 : ) scanf scnaf : scanf(, ) ;
55 42 : ( ) : 2,, &, x, &x x : %, % [ * ] [ ] [ ] : :, : l( long), ; h( short), * :, : scanf( % 4d% * 3d% f, &j, &p ) ; , j = 1234, p = 8. 9 :, scanf d o x u f e c s ( ), 2 : 1, ; 2, scanf : scanf, ( ) :
56 C scanf( % 5d, &a) ; a, scanf( % 4d% 4d, &a, &b) ; : a, 5678 b scanf,,, TAB C, TAB, : scanf( % d, &a) ; : 12A a scanf( % d% d% d, &a, &b, &c) ;, Tab a = 5, b = 6, c = 7, : TAB 6 TAB 7,, : c scanf( % c% c% c, &a, &b, &c) ; : pqr p a, b, q : scanf( % d, % d, % d, &a, &b, &c) ;,, : 5, 6, 7 = 7 scanf( a = % d, b = % d, c = % d, &a, &b, &c ) ; a = 5, b = 6, c,, % *, : scanf( % d, % * d, % d, &a, &b) ; : 1, 2, 3, 1 a, 2, 3 b, : ( Tab) ; ; scanf,, { int a, b, c; printf( % d \n, scanf( % 3d - % 2d - % 4 d, &a, &b, &c) ) ; printf( a = % d, b = % d, c = % d \ n, a, b, c) ; 43
57 , ,, : 3 a = 123, b = 45, c = , 2, : 2 a = 12, b = 34, c = xx( ) 3 ) getchar putchar 44 / getchar ; putchar putchar : putchar( ) : ( ) : : putchar( A ) ; A putchar( x) ; x putchar( \ n ) ;,, : getchar : getchar( ) :,, : char ch; ch = getchar( ) ; getchar( ), : getchar,, / stdio. h I / O : stdin stdout stderr, I / O { putchar( ) char ch1 = N, ch2 = E, ch3 = W ; putchar( ch1) ; / * ch1 * / putchar( ch2) ; putchar( ch3) ; putchar( \ n ) ; / * * /
58 C putchar( ch1) ; putchar( \n ) ; / * ch1, * / putchar( E ) ; putchar( \ n ) ; / * E, * / putchar( ch3) ; putchar( \n ) ; : NEW { char c1, c2; int b; c1 = A ; N E W printf( Please input two character: ) ; c2 = getchar( ) ; / * 1 c2* / b = 65 ; putchar( A ) ; putchar( \101 ) ; putchar( c1) ; putchar( b) ; putchar( c2) ; : Please input two character: : b : AAAAb , :,,,,, 3 C ( ) / ;
59 46, : ( ),, :,, ; ; ; ( ) H, F,? ( 1) :, ( 2) :, X, Y, :, : X + Y = H 2X + 4Y = F X = 4H - F, Y = F - 2H 2 2 ( 3) :,,,, : ( ) : ( ) : ; ; ( ) : : ; ( 4) ( 2. 5 ),,,, : : : h, f input: h, f output: x, y 2. 5
60 C x < - ( 4* h - f) /2 y < - ( f - 2* h) /2 : x, y :, x = ( 4* h - f) /2 x = ( 4 * f - h) /2,,,,,,, ( 5) : { int h, f, x, y; printf( Enter Number of Heads and Feet: h, f\ n ) ; scanf( % d, % d, &h, &f) ; x = ( 4* h - f) /2; y = ( f - 2* h) /2; printf( Head = % d, Feet = % d \ n, h, f) ; printf( Cock = % d, Rabbit = % d \ n, x, y) ; ( 6) ( ) ( 7) ( ),,,, h f,, 2. 21, ( 1) :, : ( 2) ( ) : : input: ( length), ( width) output: ( girth), ( area) : length, width girth < - ( length + width) * 2 area < - length * width = 2 ( + ) = 47
61 48 : girth, area ( 3) : { float length, width, girth, area; / * * / printf( Enter the length and width: ) ; scanf( % f, % f, &length, &width) ; / * * / girth = ( length + width) * 2; / * * / area = length* width; / * * / printf( Girth = % f\n, girth) ; / * * / printf( Area = % f\ n, area) ; / * * / : Enter the length and width: 1. 2, Girth = Area = , ASCII, ASCII ( 1) : a ASCII = 97, A ASCII = 65, a - A 32;, ASCII = 32 ( : a - A ) ( 2) ( ) ( ) ( 3) : { char c1, c2; printf( Input a lowercase letter: ) ; c1 = getchar( ) ; putchar( c1) ; printf(, % d \ n, c1) ; c2 = c1-32; /* : c2 = c1 - ( a - A ) * / printf( % c, % d \ n, c2, c2) ; : Input a lowercase letter: a a, 97 A, 65
62 C ( 1) ( A) abc ( B) abc ( C) abc ( 2) C, ( D) a ( A) 0 L ( B) ( C) ( D) e12 ( 3) int a = 3 ;, a + = a - = a * a;, a ( A) 3 ( B) 0 ( C) 9 ( D) - 12 ( 4), ( a = 2, b = 5, b + +, a + b ) ( A) 7 ( B) 8 ( C) 6 ( D) 2 ( 5) : int k, a, b; unsigned long w = 5; double x = 1. 42; C ( A) x% ( - 3) ( B) w + = - 2 ( C) k = ( a = 2, b = 3, a + b) ( D) a + = a - = ( b = 4) * ( a = 3) ( 6) 18 /4* sqrt( 4. 0) /8 : ( A) int ( B) float ( C) double ( D) ( 7) int x, y; double z;, scanf ( A) scanf( % d% lx, % le, &x, &y, &z) ;( B) scanf( % 2d * % d% lf &x, &y, &z ) ; ( C) scanf( % x % * d% o, &x, &y) ; ( D) scanf( % x% o% 6. 2f, &x, &y, &z) ; ( 8), a1, a2, c1, c2 10, 20, A, B,, int a1, a2; char c1, c2; scanf( % d% d, &a1, &a2) ; scanf( % c% c, &c1, &c2) ; ( < > ) ( A) 1020AB ( B) AB ( C) AB ( D) AB ( 9) C, sizeof( float) ( A) sizeof ( B) ( C) ( D) 49
63 ( 1)?? ( 2) C,?? ( 3) C,? 2. 3, ( 1) # include < stdio. h > { / * * / int a = 5 ; char c = a ; float f = 5. 3; double m = ; double result; / * * / printf( a + c = % d \ n, a + c) ; printf( a + c = % c \ n, a + c) ; printf( f + m = % f\ n, f + m) ; / * * / printf( a + m = % f \n, a + m) ; printf( c + f = % f\ n, c + f) ; / *, * / result = a + c * ( f + m) ; printf( double = % f\ n, result) ; ( 2) { int a = 5, b = 7; float x = , y = ; char c = A ; long n = ; unsigned u = ; printf( % d% d \ n, a, b) ; printf( % 3d% 3d \n, a, b) ; printf( % f, % f \n, x, y) ;
64 C printf( % - 10f, % - 10f\ n, x, y) ; printf( % 8. 2 f, % 8. 2f, % 4f, % 4f, % 3f, % 3f\ n, x, y, x, y, x, y) ; printf( % e, % 10. 2e \ n, x, y) ; printf( % c, % d, % o, % x\ n, c, c, c, c) ; printf( % ld, % lo, % x \ n, n, n, n) ; printf( % u, % o, % x, % d \ n, u, u, u, u) ; printf( % s, % 5. 3s \ n, COMPUTER, COMPUTER ) ; ( 3) # include < stdio. h > { int i, j, k; int m, n, p; i = 8; j = 10 ; k = 12; / * * / m = + + i; printf( i = % d \ n, i) ; printf( m = % d \ n, m) ; / * * / n = j - - ; printf( j = % d \ n, j) ; printf( n = % d \ n, n) ; / * * / p = ( + + m) * ( n + + ) + ( - - k) ; printf( k = % d \ n, k) ; printf( p = % d \ n, p) ; ( 4) { 2. 4 int x = 0, y = - 1, z = - 1; x + = - z y; printf( % d, % d, % d \n, x, y, z) ; 51
65 ( 1) r = 1. 5, h = 3, scanf,,, ( 2) ASCII ( 3) 30, 90, 52
66 C 3. 1 C 53, C C,,, 3 3 :,, 3. 1,,,,,,
67 C , 2 C 6, 3. 1 : 3. 1 < < = > > = ==! = ( ) ( ) 6, 4 ( < < = > > = ), 2 ( ==! = ), 2 2 ( ) : 1 2 : a + b > c - d, x > 3 /2, a + 1 < c, - i - 5 * j == k + 1, ( a > b) > ( b < c )
68 C C,, 1, 0, ; : a = 3, b = 2, c = 1, : a > b, 1 ( a > b) == c ( a > b 1, c ), 1 b + c < a, 0 : : d = a > b, f = a > b > c, : d 1 f 0 ( a > b 1, c, f = 0) : num1 = 3, num2 = 4, num3 = 5, : num1 > num2 = 0 ( num1 > num2)! = num3 = 1 num1 < num2 < num3 = 1 ( num1 < num2) + num3 = 6, num1 < num2 = 1, = 6 : C 1, 0,,, 3. 1 / * ex3-1. cpp * / { int x = 1, y = 2, z; z = 5-1 > = x + 2 < = y + 3; /* * / printf( z = % d \n, z) ; : z = , x > = 0 x > = 0 x < 10, C 3, ! ( ) && ( ) ( )
69 56 : &&,,,!,,,!, &&, :! ( ) &&( ) ( ) : ( a > b) && ( b > c ) b > d : ( ( a > b) && ( b > c) ) b > d, : b a c, b d :! && 2 ( ) : 1 2, : ( x > = 0) && ( x < 10) ( x < 1) ( x > 5 )! ( x == 0) ( year% 4 == 0) &&( year% 100! : x 0 x < 10 : x < 1 x > 5 : x 0 100, year 400! ( b == c) d < a a + b > c && x + y < b = 0) ( year% 400 == 0) : year 4 : b c a > d : a + b > c x + y < b 2, &&( ) ( ) 5 > 0 && 4 > 2 2, 5 > 0, 4 > 2,, 2, 5 > 0 5 > 8, 2 5 > 0,,! ( ), ;,! ( 5 > 0) C, 1, 0,, 0, 0 : 5 3 0, 5&&3, 1
70 C : 5 0, 1 : num = 12,! num 0; num > = 1 && num < = 31 1; num num > 31 1 C, 2 :,, :,, :,, ;,, : a && b && c, a, b ; a b, c a, b c,, a b c, a, b c, a, b ; a b, c, / * ex3-2. cpp * / { int a, b, c, d, j, k; a = 1, b = 2, c = 3, d = 4, j = k = 1 ; ( j = a > b) &&( k = c > d) ; / * * / printf( j = % d, k = % d \ n, j, k) ;
71 58 : j = 0, k = 1 : ( j = a > b), j 0, ( j = a > b) &&( k = c > d) 0 ;, ( k = c > d), k { int a, b, c, d; / * * / a = 1; b = 2; c = 0; / * * / d = a + b > c; / * * / printf( " % d \n", d) ; d = a + b < c; / * * / printf( " % d \n", d) ; d = a + c == b; / * * / printf( " % d \n", d) ; d = a ++ &&b ++++ &&c ++ ; / * * / printf( " a = % d, b = % d, c = % d, d = % d \ n", a, b, c, d) ; d = a ++ b ++ &&c ++ ; / * * / printf( " a = % d, b = % d, c = % d, d = % d \ n", a, b, c, d) ; : a = 2, b = 3, c = 1, d = 0 a = 3, b = 3, c = 1, d = ,,
72 C ( ), :, C C, 2 : if switch, if if 3 : if else if if else if else ( 1) if ( if-else ) : if( ) 1; else 2; :, ( 0 ), 1, if ;, 2, if 3. 4 : if ( ) 3. 4,,, 1 2, else ( ) if, if, 3. 4 a, a ( a 0) ( 1) : a - a ( a < 0) ( 2) ( ) : 59
73 60 a if( a > 0) then b = a else b b = - a ( 3) C : { float a, b; scanf( " % f", &a) ; if( a > = 0) else b = a; b = - a; printf( " The absolute value of % f is % f \n", a, b) ;,, 1 2, 3. 5,,, ( 1) :, a b c, : ( : a + b > c a + c > b b + c > a ) : ( ) : a, b, c if ( ) then else s = ( a + b + c) /2; s = ( a + b + c) /2 area = s( s - a ) ( s - b) ( s - c) area = sqrt( s* ( s - a) * ( s - b) * ( s - c) ) ; : area : " error" ( 3) C :
74 C #include < math. h > { float a, b, c, s, area; scanf( " % f, % f, % f", &a, &b, &c) ; if( a + b > c && a + c > b && b + c > a) { s = ( a + b + c) /2; area = sqrt( s* ( s - a) * ( s - b) * ( s - c) ) ; printf( " % f\ n", area) ; else printf( " data error \n" ) ;, ; 1 ; ( sqrt),, math. h, #include < math. h >, main if, C, if : 3 x, y, z, 2 x, y, max ; z max, max ;, max 3 ( 2) ( ) : : x, y, z if( x > y) then max = x else max = y if( z > max) then max = z : max ( 3) C : / * ex3-6. c* / { int num1, num2, num3, max; 61
75 62 printf( " Please input three numbers: " ) ; scanf( " % d, % d, % d", &num1, &num2, &num3) ; if ( num1 > num2 ) max = num1 ; else max = num2 ; if ( num3 > max) max = num3 ; printf( " The three numbers are: % d, % d, % d \ n", num1, num2, num3) ; printf( " max = % d \n", max) ; 1 if, else : max = num1; if( num2 > max) max = num2; : max( ), max, max, max,, max 3 3 ( 2) if ( if ) : if( ) ; :, ( 0),, if ; ( 0), if : if ( ),,,,
76 C if else else 3. 7, ( if ) { float a; 3. 8 scanf( " % f", &a) ; if( a < 0) a = - a; printf( " % f\ n", a) ;,, ( 1) ( ) : : x if( x 2 ) then x, : x ( 2) C : / * ex3-8. cpp * / { int x; printf( " input: x \n" ) ; / *, * / scanf( " % d", &x) ; if( x% 2) / * : x 2, 0* / printf( % d is odd number. \ n, x) ; ( 3) if ( if else ) if if, if : 63, if
77 : 1,, 2,, 1; 2 2 ; 1, 3,, 3; 4, : C,, : if else if ; if if ( else ) if, else if : else if : if ( 1) if ( 2 ) 1 else if ( 3 ) 2 else 3 else if,, else if,,?,,,, ( if else, ), if ( 1) { if ( 2 ) 1
78 C else if ( 3 ) 2 else 3,, : if, { 3. 9 : { int x, y; y = scanf( " % d", &x) ; if ( x < 1) y = x; if ( x > = 1 && x < 10) y = 2* x - 1; if ( x > = 10) y = 3* x - 11; printf ( " % d, % d", x, y) ; x ( x < 1) 2x - 1 ( 1 < x < 10) 3x - 11 ( x 0), ( 1) : ; 400 ( 2) : : year if( ( year 4 ) ( year 100 ) ( year 400 ) ) else leap = 1 leap = 0 if ( leap = 1) else ( year, ) ( year, ) 65
79 66 ( 3) C : { int year, leap; scanf( " % d", &year) ; if( ( year% 4 == 0) &&( year% 100! = 0) ( year% 400 == 0 ) ) leap = 1; else leap = 0; if ( leap) printf( " % d is a leap year \ n", year) ; else printf( " % d is not a leap year \n", year) ; :, ( 4) elseif ( if elseif else ) if else, else if, if else ( : if elseif else ) : if( 1) 1 else if ( 2) 2 else if ( 3) 3 else if ( m) m else m + 1 : 1,, 1; 2 :,, 2; 3,, 3; m,, m, m , 2 ; 2
80 C 3. 7, 3, else, 1, 0( ),, ; 0 ( ), m + 1, else m , 5% ; 100, 7. 5% ; 300, 10% ; 500, 15% ; 50, 0? { float total, con; scanf( " % f", &total) ; if ( number > 500) con = ; else if ( number > 300) con = ; else if ( number > 100) con = ; else if ( number > 50) con = ; else con = 0; printf( " % f", total - total* con) ; , 67
81 68 { long num, place; printf( " ( ) : " ) ; scanf( " % ld", &num) ; if( num > 9999 ) place = 5; else if( num > 999) place = 4; else if( num > 99) place = 3; else if( num > 9 ) else place = 2; place = 1; printf( % ld % d! : \ n, num, place) ; { int x, sign; sign( x) = printf( Please input a number \ n ) ; scanf( % d, &x) ; if( x > 0) sign = 1; else if( x = = 0) else sign = 0; sign = - 1; printf( The sign is % d \ n, sign) ; 2 ) - 1 ( x < 0) 0 ( x = 0) 1 ( x > 0) if, 2 :
82 C ( ), ; C if?:, C, 3 : 1? 2: 3 : 1, 1 0 ( ),, if : 2 ; 1 0 ( ), 3 if( x < y) else max = y; max = x; if :, : max = ( x < y)? y: x,, max = ( a > b)? a: b max = a > b? a: b? :, : a > b? a: c > d? c: d a > b? a: ( c > d? c: d),, { float a, b, sum; a + b printf( " Input 2 reals: " ) ; scanf( " % f, % f", &a, &b) ; sum = b > 0. 0? a + b: a - b; printf( a + b = % f\ n, sum) ;,, ;, { char ch; printf( " Input a character: " ) ; 69
83 scanf( " % c", &ch) ; ch = ( ch > = A && ch < = Z )? ( ch + 32) : ch; printf( " ch = % c \ n", ch) ;, if 3 ) switch case ( ) 70 if, if,,,, C switch, switch : switch( ) { case 1 : 1; [ break; ] case 2 : 2 ; [ break; ] case n: n; [ break; ] default: n + 1 :,, case, ; break, :, number, number 2, statement2,, break, switch, statement5, :, number, number 2, statement2,, break, statement3,, break, statement4,, switch, statement5
84 C :,, ( case ) case, ; case2: case 2: break default case break, case,, { case : case A : case B : case C : printf( " > 60 \ n" ) ; break; A B C3, default, ; default, default, default break switch : case switch { int x = 1, y = 0, a = 0, b = 0 ; switch( x) { case 1: switch( y) { case 0: a ++ ; break; case 1: b ++ ; break; 71
85 72 case 2: a ++ ; b ++ ; break; case 3: a ++ ; b ++ ; printf( " a = % d, b = % d \n", a, b) ;, { char grade; printf( " input the grade: " ) ; scanf( " % c", &grade) ; switch( grade) { case A : printf( " \ n" ) ; case case break; B : printf( " \ n" ) ; break; C : printf( " \ n" ) ; break; case D : printf( " < 60 \ n" ) ; break; default: printf( " error \ n" ) ; { char grade; 60 printf( " Input the grade: " ) ; scanf( " % c", &grade) ; switch( grade) { case A : case B : case case C : printf( " > = 60 \ n" ) ; break; D : printf( " < 60 \ n" ) ; break;
86 C { char c; default: printf( " error \n" ) ;, ;, int i = 0; c = getchar( ) ; switch( c) { case 9 : i ++ ; case 8 : i ++ ; case 7 : i ++ ; case 6 : i ++ ; case 5 : i ++ ; case 4 : i ++ ; case 3 : i ++ ; case 2 : i ++ ; case 1 : i ++ ; case 0 : printf( " It is a digiter % d. \ n", i) ; break; case : printf( " It is a space. \n" ) ; break; default: printf( " It is other character. \n" ) ;, { int year, month, days; printf( " input year, month =? \ n" ) ; scanf( " % d, % d", &year, &month) ; switch( month) { case 1: case 3: case 5: case 7: case 8: 73
87 74 case 10: case 12: days = 31; break; case 4: case 6: case 9: case 11: days = 30; break; case 2: if( ( year% 4 == 0 ) &&( year% 100! = 0) ( year% 400 == 0) ) days = 29; else days = 28; break; default: printf( " month is error \ n" ) ; printf( " year = % d, month = % d, days = % d \n", year, month, days) ; ,,, ;, 3, C, 3, : while do while for while while while, :
88 C, while : while( ) :, 0 ( ), ;, 0 ( ),, 0 ( ),, ; 3. 8 while : 3. 8 while while, 0,, C while n n = 1 ( 1) : sum, 0, sum + = n ( n 1, 2, 100), 3 : n 1 ; 1 sum + = n, n 1 ; n 101,, sum ( 2) : sum n, 0; n < = 100,, ; sum + n sum, n + 1 n; ; sum. ( 3) : sum 0, n 1 While( i < n) Sum sum + i n n + 1 : sum
89 76 ( 4) C : { int n = 1, sum = 0; while( n < = 100) { sum + = n; / * sum = sum + n; * / n ++ ; printf( sum = % d \ n, sum) ; { char ch; 26 ch = Z ; while( ch > = A ) { putchar( ch) ; ch - - ; / *, * / printf( " \n" ) ; do while do while while,, : do while( ) ; :, 0( ), ;, ; 0( ),, 0( ),, ; 3. 9 do while : do while,,
90 C, { C, while( ) 3. 9 donwhile { int n, sum; n = 1, sum = 0; do { sum + = n; n ++ ; while ( n < = 100) ; do while n n = 1 ( 1) : ( ) ( 2) C : printf( sum = % d \ n, sum) ; ( 1) :, ( 10 ), ;, ; ( 2) : : n While ( n 0) r < - ( n /10 ) ( : n 10, ) : r( ) n < - ( n /10) ( : n 10, ) ( 3) C : { int i, r; printf( " Input an integer \n" ) ; sanf( " % d", &i) ; do { r = i % 10; 77
91 printf( " % d", r) ; while ( ( i / = 10)! = 0 ) ; printf( " \n" ) ; for 78 for C for,, for for : for( 1; 2; 3 ) for 3 ; ; : ; ; 1 ( ) 2 ( ) 3 ( ) : 3. 9, 0,, ;,,, ; for for : :,, 0 1, 3 ; 2,,, 2, 3, : for ( sum = 0; i < = 100; i ++ ) sum + = i; for ( sum = 0, i = 1 ; i < = 100 ; i ++ ) sum + = i; for ( i = 0, j = 100; i < = j; i ++, j - - ) k = i + j;, C for
92 C, ; for, for C, , : a. 1 3,, while : for( ; i < = 100; ) { sum = sum + i; i ++ ; : while( i < = 100) { sum = sum + i; i ++ ; b. 3, 2 ;, for ( i = 1; i < = 100; ) { sum = sum + i; i ++ ; c. 2,,, break, goto, exit( ), return ;, : for ( i = 1; ; i ++ ) sum = sum + i; : while ( 1 ) { sum = sum + i; i ++ ; for while do while, for while : 1; while ( 2 ) { 3; for : for : x 0 = < x < N, N, N ; for ( int x = 0; x < N; x ++ ) { x 0 = < x < = N - 1, N - 1, N ; for ( int x = 0; x < = N - 1; x ++ ) {,, for n n = 1 ( 1) : ( ) ( 2) C : { int n, sum = 0; 79
93 80 for( n = 1; n < = 100; n ++ ) sum + = n; printf( sum = % d \ n, sum) ; n n! ( n! = n) ( 1) : fact, 1, fact = fact* fact 1; 1 fact = fact* i ( i 1, 2,, n), 3 : i, i 1; i n,, fact n! ( 2) 5 : fact n i; i = 1, fact = 1; i < = n,, ; fact* ; fact i fact, i + 1 i; ( 3) : : n fact 1, i 1 While( i < = n) fact fact* i : fact ( 4) C : { int i, n; long fact = 1; / * fact 1* / printf( Input n: ) ; scanf( % d, &n) ; for( i = 1 ; i < = n; i ++ ) fact * = i; / * * / printf( " % d! = % ld \ n", n, fact) ; 2, ( 1) : 1, m, 2 m - 1 m, m, m, m, m
94 C ( 2) : : num( : num > 2) flag 0 ( num ), i 2 while( i < = num - 1) if( num i ) flag = 1( num ) ; if( flag = 0) : num, " " else : num, " " ( 3) C : #include < math. h > { int m, i, flag; flag = 0; scanf( " % d", &m) ; for( i = 2 ; i < m - 1; i ++ ) if( m % i == 0) flag = 1; if( flag == 0) printf( " % d is a prime. ", m) ; else printf( " % d is not a prime. ", m) ; while do while for 3,, 3 : 3 ( while do while for), while do while, while ;, ( ) for 3, 3 for, while
95 , for while do while, while do while for 1 while for,, ; do while,, ,,,, ;, ( ) C 3 do while while for : while while for for do while do while while for :, : ;, 3. 27
96 C A BB CCC DDDD EEEEE ( 1) : 5, ; A, B C D E ( ASCII : A + i 64 + i) ;, ( 2) : i 1 j 1 : ch A While( i < = 5) While( j < = i) i i + 1 : ch j j + 1 ch < - ch + 1 ( 3) C : { int i, j; char ch; ch = A ; for( i = 0 ; i < 5; i ++ ) { for( j = 0 ; j < = i; j ++ ) printf( " % c", ch) ; + 1; * / printf( " \n" ) ; ch = ch + 1; { int i, j; printf( " * " ) ; /* printf( " % c", ch + i) ; ch = ch 83
97 84 for( i = 1 ; i < = 9; i ++ ) / * * / printf( " % 4d", i) ; printf( " \n" ) ; for( i = 1 ; i < = 9; i ++ ) / * * / { printf( " % 4d", i) ; / * * / : for( j = 1 ; j < = i; j ++ ) / * * / printf( " % 4d", i* j) ; / * * / printf( " \n" ) ; / * * / * a b, a b :, 1, 2 : n, 2 n /2 n,, n n, 2 n n,, n ( 2) : n, for n :, 2 ( n - 1 ) n,,, 0 ( 3) ( ) : : : a, b num a
98 C while( num < = b) k num i 2 while( i < = k) if( num i ) num, num; else : num ; num; i i + 1 num num + 2 ( 4) C : #include < math. h > { int a, b, num, i, k; scanf( " % d, % d", &a, &b) ; for( num = a; num < = b; num ++ ) { k = sqrt( num) ; for( i = 2 ; i < = k; i ++ ) if( num% i == 0) break; if( i > k) / * break : i < k * / printf( " % d is a primenumber. \ n", num) ; C, for, while, do while,,,, CPU, ( b) ( a)
99 for ( row = 0; row < 100; row ++ ) { for ( col = 0; col < 5; col ++ ) { sum = sum + row* col; ( a) : for ( col = 0; col < 5; col ++ ) { for ( row = 0; row < 100; row ++ ) { sum = sum + row* col; ( b) :,, ( c) ( d) N - 1,,, N, ( d), N,, ( c), 86 for ( i = 0; i < N; i ++ ) { if ( condition) DoSomething( ) ; else DoOtherthing( ) ; ( c) if ( condition) { for ( i = 0; i < N; i ++ ) DoSomething( ) ; else { for ( i = 0; i < N; i ++ ) DoOtherthing( ) ; ( d) goto goto, : goto ; goto : :
100 C,, goto, goto if,, : for( ) { if c then goto L; L:, goto, goto,, goto,, goto, goto,,, goto, : goto state; float s1, s2; / / goto int sum = 0; / / goto state:, goto goto,,, goto goto,,, break ; : { for { for { for if( disaster) goto error; error:,, goto,, goto if, goto 87
101 1 100 : { int k = 1, sum = 0; loop: if( k < = 100) sum + = k; k ++ ; goto loop; printf( % d \n, sum) ; C, goto break 88 break break break : break; : switch : switch ; " break " switch while for do while break break C : { int i; for( i = 1 ; i < = 100 ; i ++ )
102 C { printf( " % d ", i) ; if( i > 9) printf( " \n" ) ; break; ( 1) : : 1 100, 13, j 100, ;, 13 ; 13, 13 ;, ( 2) ( ) ( 3) C : { int j; for( j = 100; j > = 0 ; j - - ) / * j 100, * / if( j% 13 == 0 ) / * 13 * / break; / * 13, * / printf( % d \n, j) ; continue continue, : continue; : :, : continue, while for do while continue n : ( 1) : sum = n, ( 10 ), ;, ;
103 90 ( 2) : LIMIT 10 n 1, sum 0 while( sum < LIMIT) an 1 /n sum sum + an n < n + 2 : n ( 3) C : #define LIMIT 10 { int n = 1; float sum = 0. 0; for( ; ; ) { sum = sum / n; if( sum > LIMIT) break; n ++ ; printf( " n = % d \ n", n) ; ( 1) : : 1 100, 7 : j 1, ;, 7 7,, ;,, ; j > 100, ( 2) : num 1 while( num < = 100)
104 C if( num 7 ) else, num;, num; num num + 1 ( 3) C : { int num; for( num = 1; num < = 100; num ++ ) { if( num% 7 == 0) continue; / * 7,, * / printf( % d \ n, num) ; , ( 1) : 3 x, y, z, x, y, x, y, x z, x, z ; y z, y ; z ;, 3 : x < y < z ( 2) ( ) : : input: x, y, z output: x, y, z( x < y < z) : x, y, z : x, y, z if( x > y) then x y
105 92 if( x > z) then x z if( y > z) then y z : x, y, z ( 3) C : { int x, y, z, temp; printf( Input x, y, z \ n" ; scanf( % d, % d, % d, &x, &y, &z) ; printf( % d, % d, % d \ n, x, y, z) ; if( x > y) if( x > z) emp = x, x = y, y = temp; temp = x, x = z, z = temp; if( y > z) temp = y, y = z, z = temp; printf( x < y < z: % d, % d, % d \ n, x, y, z) ; a x 2 + bx + c = 0 ( 1) :, : a b 2 b 2 b 2 = 0, - 4a c = 0, 2-4a c > 0, 2-4a c < 0, 2 ( 2) ( ) : : input: a, b, c temp: d( d = b 2 output: x1, x2 : a, b, c if( a = 0) then d < b 2 : " " - 4ac if( d = 0) then - 4ac), p, q x1, x2 < - b / ( 2* a)
106 C : " x1 = x2 = : ", x1 if( d > 0) then x1 < ( - b + sqrt( d) ) /( 2 * a) ; x2 < ( - b - sqrt( d) ) /( 2 * a) ; : " x1", x1, " x2 = ", x2 if( d < 0) then p < - b / ( 2* a) q < qrt( - d) /( 2* a) : " : ", x1, x2 ( 3) C : #include < math. h > { float a, b, c, d, x1, x2, p, q; printf( " a, b, c =?" ) ; scanf( " % f, % f, % f", &a, &b, &c) ; / * * / printf( " The equation" ) ; if ( fabs( a) < = 1e - 6) / * a = 0 * / printf( " is not quadratic" ) ; else { d = b* b - 4* a* c; /* * / if( fabs( d) < 1e - 6 ) /* = 0 * / printf( " has two equal roots: % 8. 4f\ n", - b / ( 2* a) ) ; else if( d > 1 e - 6) /* > 0 * / { x1 = ( - b + sqrt( d) ) / ( 2* a) ; x2 = ( - b - sqrt( d) ) / ( 2* a) ; printf( " has distinct real roots: % 8. 4 f and 8. 4f\ n", x1, x2) ; else /* < 0 * / { p = - b / ( 2* a) ; q = sqrt( - d) / ( 2* a) ; printf( " has complex roots: \n" ) ; printf( " % 8. 4f + % 8. 4fi \ n", p, q) ; printf( " % 8. 4f - % 8. 4fi \ n", p, q) ; 93
107 , profit( ) ( : ) : profit ; 1000 < profit % ; 2000 < profit % ; 5000 < profit % ; < profit 25% ( 1) : switch, profit, ( 1 000, 2 000, ), profit 1 000, : profit , < profit , < profit , 3, 4, < profit , 6, 7, 8, 9, < profit 10, 11, 12 ( 2), : profit 1 ( ), 1000 : profit < profit < profit , 3, < profit , 6, 7, 8, < profit 10, 11, 12 ( 2) ( ) : ( ) ( 3) C : { long profit; int grade; float salary = 500; /* * / printf( " Input profit: " ) ; scanf( " % ld", &profit) ; /* profit* / grade = ( profit - 1 ) / ; / * , switch case * / switch ( grade) { case 0: break; /* profit 1000 * / case 1: salary + = profit* 0. 1; break; /* 1000 < profit 2000 * / case 2:
108 C case 3: case 4: salary + = profit* 0. 15; case 5: case 6: case 7: case 8: break; /* 2000 < profit * / case 9: salary + = profit* 0. 2; break; /* 5000 < profit * / default: salary + = profit* 0. 25; /* < profit * / printf( " salary = %. 2f \n", salary) ; 2, ( + - * / ), ;, ( 1) :,, if - else if, switch switch, switch, ( 2) ( ) : ( ) ( 3) C : { int a, b, d; char c; printf( " Enter Two Numbers: " ) ; scanf( " % d, % d", &a, &b) ; printf( " Enter Operator( +, -, *, / ) : " ) ; scanf( " % c", &c) ; switch ( c) { case + : d = a + b; printf( " % d + % d = % d \ n", a, b, d) ; break; case - : d = a - b; printf( " % d - % d = % d \ n", a, b, d) ; break; case * : d = a* b; printf( " % d* % d = % d \ n", a, b, d) ; break; 95
109 case / : if( b == 0) printf( " Divisor is zero\ n" ) ; else { d = a / b; break; printf( " % d /% d = % d \n", a, b, d) ; default: printf( " Input Operator error! \n" ) ;, 1 ( 1) : n: 1 200, n, m* m == n ( : 1 < m < sqr( n) ),,, n ;,, n ; n > 100, ( 2) : n 1 while( n < = 200) m 1 while( m < sqr( n) ) if( m* m = n) else m < m + 1 n < - n + 1 ( 3) C : #include < math. h > void main ( ) { int m, n;, num;, num; for ( n = 1; n < = 200; n ++ ) for ( m = 1; m < = sqrt( n) ; m ++ ) if ( m * m == n) printf( " % d ", n) ; printf( " \n" ) ;
110 C sin( x 3 ) = x - x 3 /3! + x 5 /5! - x 7 /7! +, 10-7 ( 1) : : F n n, F n + 1 n + 1, F n + 1 x 2 = - F n 2n ( 2 n + 1 ), x ( 2) : : x, EPS k 1, an x, sum 0, n 1 while( an < EPS) sum sum + an an an* ( x* x) / ( ( 2* n* ( 2* n + 1) ) * k k - k n n + 1 : x, sum ( 3) C : #include < math. h > #define EPS 1e - 7 #define PI { int n; double x, an, sum; printf( " input x: " ) ; scanf( " % lf", &x) ; x = x* PI /180; / * * / sum = 0; an = x; n = 1; / * an * / do { sum + = an; an* = ( - x* x) / ( ( 2 * n* ( 2* n + 1 ) ) ; /* * / ++ n; while( fabs( an) > = EPS) ; / * fabs( ), * / printf( " sin( %. 4f) = %. 4f \n", x, sum) ; 97
111 ,, A Z, a z, : A E, a e, 4 ; W A, X B, Y C, Z D, China! Glmre!, ( 1) : ;, : 4 ( ASCII + 4 ), ( A E, a e) ( 2) ( ) : ch while( ch ) if( ch ) ch ch + 4 if( ch ) ch ch - 26 : ch ch ( 3) C : { char c; while ( ( c = getchar( ) )! = \ n ) { if( ( c > = a &&c < z ) ( c > = A &&c < = Z ) ) { c = c + 4; if( c > Z &&c < Z + 4 c > z ) c = c - 26; printf( " % c", c) ;
112 C ) ( GCD) ( LCM) ( 1) : 2 m n( m > n) ( ) : 2 m n( m > n) ; m n, r( 0 < = r < n) r 0, r 0, ; r = 0, n,, n > m, r > n r m n ; n, n 2 m n ( GCD), ( LCM) : 2 ( 2) : : num1, num2 if( num1 < num2) num1 num2, ( m > n) m num1, n num2 while( n 0 ) GCD m r m n ) m n( m = n) n r ( n = r) LCM num1* num2 / m : :, GCD : :, LCM ( 3) C : { int m, n, num1, num2, temp; printf( " Input two positive integer: \ n" ) ; scanf( " % d, % d", &num1, &num2) ; 99
113 if( num1 < num2) /*, num1 num2, ( m > n) * / temp = num1, num1 = num2, num2 = temp; m = num1; n = num2; while( n! = 0) { temp = m% n; m = n; n = temp; printf( " The greatest common divisor is: % d \ n", m) ; printf( " The lowest common multiple is: % d \ n", num1* num2 / m) ; 2 ) 100 :,, ( ) 2 : (,,, ) (, ) , 36 ; 4, 3, 2 1,? ( 1) :, : ( men) : 1 8 ( women) : 1 12 ( childs) : : 4* + 3* + /2 = 36 ( 2) : men 1 while( men < 9) women 1 while( women < 12 ) else childs 36 - men - women if( 36 ) ( men, women, childs), ;, ;
114 C ( 3) C : { int men, women, childs; for( men = 1; men < 9; men ++ ) for( women = 1 ; women < 12; women ++ ) { childs = 36 - men - women; if( 4* men + 3* women + childs/2. 0 = = 36) printf( " men = % d, women = % d, childs = % d \ n ", men, women, childs) ; : childs/2. 0 childs/2, C 2,, ( 1) ( ) : m = 6 m < = ,, n1 = 2 n1 < = m /2,,, n1,,, n2 = m - n1, m = n1 + n2,, n1 = n1 + 1, m = m + 2, ( 2) : ( ) ( 3) C : #include < math. h > { int flag, flag1, k, m, n; for( m = 6; m < = 2000; m = m + 2) for( n1 = 2; n1 < = m /2; n1 ++ ) { flag = 0; for( k = 2; k < = ( int) sqrt( n1) + 1; k ++ ) if( n% k = = 0) { flag = 1; 101
115 102 break; if( flag = = 0) { flag1 = 0; n2 = m - n1; for( k = 2 ; k < = ( int) sqrt( n2) + 1; k ++ ) if( ( m - n) % k == 0) { flag1 = 1; break; if( flag1 == 0) { printf( " % d = % d + % d \n", m, n1, n2) ; break; 3. 44, 2, 1 ; 3, 2 ; 5, 4 ; 6, 5 ; 7,? ( 1) :, 7 ; 7, 7,, ; 14 ( 2) : : input: ladders( : 7, 7 ) temp: k( : k = 1, ; k = 0, ) output: ladders( ) ladders < -7( 7 ) while( k) if( ) then ladders < - ladders + 14 ladders ( 3) C :
116 C { int ladders = 7; while( ladders% 3! = 2 ladders% 5! = 4 ladders% 6! = 5) ladders + = 14; printf( flight of stairs = % d \ n, ladders) ; 3 ) 3 : ; ; ( ) ( Fibonacci ) 1, 3 1,, 1?, ( Fibonacci) : 1, 1, 2, 3, 5, 8, 13, 21, 34 ( 1) : : 3,, fn_1 = fn_2 = 1 fn = fn_1 + fn_2, C : fn_2 = fn_1 ; fn_1 = fn ( 2) : FN1 1, FN2 1 : FN1, FN2 i 3 while( i N ) fn = fn_1 + fn_2; / * 1 2 * / FN FN1 + FN2 / * i * / : FN / * i * / FN2 FN1 FN1 FN ( 3) C ( 20 ) : 103
117 { int i, fn, fn_1 = 1, fn_2 = 1; printf( " % d, % d", fn_1, fn_2) ; for( i = 3 ; i < = 20; i ++ ) { fn = fn_1 + fn_2; printf( ", % d", fn) ; fn_2 = fn_1; fn_1 = fn; 4 ) 104 f( x) = 0, f( x) = 0 : x = ( x) ; x0, : x0, x1, x2, x3,, xn, ;,,, f( x) = 0,, ( ),, x 3-4 x x - 6 = ( 1) :, x k f( x) = 0 x*, P k ( x k, f( x k ) ) f ( x) : y = f ( x k ) + f ( x k ) * ( x - x k ) X : f( x k ) + f ( x k ) * ( x - x k ) = 0, : x k+ 1 = x k - f ( x k ) / f ( x k ), x k x*,,
118 C ( 2) : x ( 1. 5) while( ) X0 X F ( ( 2* X0-4) * x0 + 3) * x0-6 / * x0 * / F1 ( 6* X0-8) * x0 + 3 / * x0 : * / x x0 - F /F1; : ( x) ( 3) C : #include < math. h > { float x, x0, f, f1 ; x = 1. 5; do { x0 = x; f = ( ( 2 * x0-4) * x0 + 3) * x0-6; f1 = ( 6* x0-8) * x0 + 3; x = x0 - f /f1; while( fabs( x - x0) > = 1 e - 5) ; printf( " root = % f \n", x) ; 105 < 0 5 ) ( ) x 4-4 x x 2-8 x - 8 = 0 ( 1) : : : f( x) = 0 x1 x2, x1 x2, f( x1 ) * f( x2) x1 x2 : x = ( x1 + x2) /2 x1 x x2 : y1 = f( x1) y = f( x) y2 = f( x2 ) y = 0,, x ;, y y1, x2 = x;, x1 = x, :, y = f( x) 0, x, f( x), 0 f( x) == 0,, f( x) 10 - k f( x) 0, f( x)
119 , x ( ) 10 - k, 10-5 ( 2) : ( ) ( 3) C : ( 10-5 ) #include < math. h > { float x1, x2, x, y1, y2, y; do / * x1 x2, x1 x2 * / { scanf( " % f, % f", &x1, &x2) ; y1 = 2 * x1* x1* x1 * x1-4* x1 * x1* x1 + 6 * x1* x1-8 * x1-8; y2 = 2 * x2* x2* x2 * x2-4* x2 * x2* x2 + 6 * x2* x2-8 * x2-8; while( y1 * y2 > 0) ; while( 1) { x = ( x1 + x2) /2; y = 2* x* x* x* x - 4* x* x* x + 6 * x* x - 8* x - 8; y1 = 2* x1* x1* x1* x1-4* x1* x1* x1 +6* x1* x1-8* x1-8; y2 = 2* x2* x2* x2* x2-4* x2* x2* x2 +6* x2* x2-8* x2-8; if( fabs( y) < 1e - 5 ) break; else if( y* y1 > 0) x1 = x; else x2 = x; printf( " x = % f\ n", x) ;
120 C 3. 7,,,,,,, ,,, ( a),,, ( b) 107 / * * / void Function1( ) { / * * / void Function2( ) { / / * / void Function3( ) { ( a) : / * * / while ( condition) { statement1; / * * / if ( condition) { statement2; else { statement3; / * * / statement4; ( b) :
121 ,,, if for while do,, {, ( a), ( b) int width; / * * / int height; / * * / int depth; /* * / x = a + b; y = c + d; z = e + f; int width, height, depth; / * * / x = a + b; y = c + d; z = e + f; 108 if ( width < height) { dosomething( ) ; for ( initialization; condition; update) { dosomething( ) ; / * * / other( ) ; ( a) : if ( width < height) dosomething( ) ; for ( initialization; condition; update) dosomething( ) ; other( ) ; ( b) : : ( ),, : int width = 10; / * width* / int height = 10; / * height* / int depth = 10; / * depth* / const virtual inline case, if for while
122 C (,, (, (, ), ;,,, Function ( x, y, z) ;,, for ( initialization; condition; update), = + = > = < = + * % && < <, ^,! & ( ) [ ]. : for if, for ( i = 0 ; i < 10; i ++ ) if ( ( a < = b) && ( c < = d) ) void Func1( int x, int y, int z) ; void Func1 ( int x, int y, int z) ; if ( year > = 2000) if( year > = 2000) if ( ( a > = b) && ( c < = d) ) if( a > = b&&c <= d) for ( i = 0; i < 10; i ++ ) for( i = 0; i < 10; i ++ ) for ( i = 0; i < 10; i ++ ) x = a < b? a : b; x = a < b? a: b; int * x = &y; int * x = & y; array[ 5] = 0; array [ 5] = 0; / * * / / * * / / * * / / * * / / * * / / * * / / * * / / * * / / * * / / * * / / * * / / * * / / * * / / * * / / * * / {, {, { ( a), ( b)
123 110 void Function( int x) { /* program code* / if ( condition) { /* program code* / else { /* program code* / for ( initialization; condition; update) { /* program code* / While ( condition) { /* program code* / {,, : { { void Function( int x) { / * program code* / if ( condition) { program code* / else { / * program code* / for ( initialization; condition; update) { / * program code* / while ( condition) { / * program code* / {,, : { { ( a) : ( b) : , 70 80,,, ; ( ),,,
124 C if ( ( very_longer_variable1 > = very_longer_variable12) && ( very_longer_variable3 < = very_longer_variable14) && ( very_longer_variable5 < = very_longer_variable16) ) { dosomething( ) ; for ( very_longer_initialization; very_longer_condition; very_longer_update) { dosomething( ) ; * &,, *, : int* x;, x int, : int* x, y; y x y, * & : char * name; int * x, y; / * y * / C / * * / : ; ;,,,,,,,
125 ,,,,,,, 112 /* * : * : * : * : * / void Function( float x, float y, float z) { if ( ) { while ( ) { / * end of while* / / * end of if* / ( 1) x [ 1, 10 ] [ 200, 210 ], ( A) ( x > = 1) &&( x < = 10) &&( x > = 200 ) &&( x < = 210) ( B) ( x > = 1 ) ( x < = 10) ( x > = 200) ( x < = 210) ( C) ( x > = 1 ) &&( x < = 10 ) ( x > = 200) &&( x < = 210) ( D) ( x > = 1) ( x < = 10) && ( x > = 200) ( x < = 210) ( 2) x y z, C : ( A) ( x > = y) AND ( y > = z) ( B) ( x > = y) && ( y > = z) ( C) ( x > = y > = z) ( D) ( x > = y) &( y > = z) ( 3 ) c 0, c a b ( A) ( a = c) &&( b = c) ( B) ( a = c) ( b = c) ; ( C) c = b = a; ( D) a = c = b; ( 4) a = 5, b = 4, ( A) ( a > b) &&( b - a) ( B) ( b > = 0) && ( a < = b? a + b: a - b) ( C) ( a < = 0) ( a% b) ( D) a &&! b
126 C ( 5) a int a, b, c; a = b = c = 1; ++ a ++ b&& ++ c ( A) ( B) 0 ( C) 2 ( D) 1 ( 6) for( i = 1; i + + < 4; ) ;, i ( A) 3 ( B) 4 ( C) 5 ( D) 1 ( 7) for( x = 0, y = 0; ( y! = 100 ) &&( x < 4 ) ; x + + ) ; ( A) ( B) ( C) 4 ( D) 3 ( 8) C while(! e) ;! e ( A) e == 0 ( B) e! = 1 ( C) e! = 0 ( D) e == 1 ( 9) i j int, for( i = 5; i; i - - ) for( j = 0; j < 4; j + + ) { ( A) 20 ( B) 24 ( C) 25 ( D) ( 1) C?? ( 2) C?? ( 3) switch - case? 3. 3, ( 2) # include < stdio. h > { / *, * / int logic; int a = 1; int b = 2; int c = 3; logic = a + b > c&&b < = c; printf( " logic = % d \n", logic) ; logic = a > = b + c b == c; printf( " logic = % d \n", logic) ;
127 logic =! ( a < c) + b! = 1 &&( a + c) /2 ; printf( " logic = % d \n", logic) ; 114 ( 2) { int a = 100, x = 10, y = 20, okl = 5, ok2 = 0; if ( x < y) if( y! = 10) if(! okl) a = 1; else if( ok2) a = 10; a = - 1 ; printf( " % d \n", a ) ; ( 3) void main3( ) { int num = 0; while( num < = 2) { num + + ; printf ( " % d \ n", num) ; ( 4), ADes iptor ( ), { char c; int v0 = 0, v1 = 0, v2 = 0; do{ switch( c = getchar( ) ) { case case a : A :
128 C case case case case case case case case e : E : i : I : o : O : u : U : v1 + = 1; default: v0 + = 1; v2 + = 1; while( c! = \ n ) ; printf( " v0 = % d, v1 = % d, v2 = % d \ n", v0, v1, v2) ; ( 5) { int x, y; for( x = 1, y = 1; y < = 50; y ++ ) { if( x > = 10) break; if( x% 2 == 1) { x + = 5 ; continue; x - = 3 ; printf( " x = % d, y = % d \ n", x, y) ; ( 1), ( :, ) ( 2),, : 123, 321 ( 3) : 3 5 7, YES, NO ( 4) : 3, ( 5) 0 m, 4 15 m,
129 ( 2, 2) ( - 2, 2) ( 2, - 2) ( - 2, - 2), 1m,, ( 0 m) ( 6 ), x, y,, y = x( x ) x1 2 x - 1 < x < 1 x - 1 x - 1 ( 7) 3, : 153 = , 153,, ( 8) e ( 10-6 ) : 116 ( 9) : ( 10) : 1 e = n = 0 n! * k * * * * * * * * * * * * * * * * * * * * * * * * AAAAAAAAAAAA BBBBBBBBBB CCCCCCCC DDDDDD EEEE FF ( 11) 3 5, 3 6, ( 12) 1 99 :, 5 25, , 5 25 ( 13) ( : n = ) ( 14) , 40, 1 ( 15) 100 m, 10? 10?
130 C ( 16) 1, 1 ; 2 1 ; 10,
131 ,,,,,,,,, :,,,,,,,,,,,,
132 ,,, C C, : C,, C,, main( ),,, C, IN- CLUDE H,,,,, C C
133 C : ( ) { ( ) : ( ) { ( ), : / * * / long fac( x) int x; { long y = 1; int k; for( k = 1; k < = x ; k + + ) y* = k; return( y) ; / * * / long fac( int x) { long y = 1; int k; for( k = 1; k < = x; k + + ) y* = k; return( y) ;
134 : C,, C : ( ) ( 1) ( ), return, ( int), ( long), ( char), ( float), ( double ),,, void ( ), : int putlll( int x, int y, int z) / * * / char * name( ) ; / * * / void student( int n, char * str) ; / * * / float calculate( ) ; / * * / : ( int) ( char ), : sum( int a, int b) ; / * * / ( 2), C, main( ),, ( 3),,, :, : int f( int a, float b) int float,, void : intf( ) intf( void),,,,,,, 121
135 122, ( 4) C, : void nothing( ) {,, C, main,,, ( max, power, ),, 2, : ( void, return) 2 : 1, : return < > ; return; 1 :,,,,, 2 : return;, return,,, (, ),,,,, return,, s1 s2 1, - 1 int find_char( char s1, char s2 ) { if( s1 = = s2 ) else return 1; return - 1; :, return
136 ;,, C, C, ( ) (, goto ),, C,, ( ) C,, C C 3 : 1,,, sqr( ) sin( ) 2,, write( ),, write( ), - 1, 3 ( ),, printf( ) scanf( ) , :,,,,,,,, : #include < > #include : #inlcude stdio. h #include,, C ( include ) ;, : ( [ ], [ ], ) ; 1 ( ), ( ) : double funa( double a, int b, float c) {
137 124, : double funa( double a, int b, float c) ; / * * /,, double funa( double, int, float) ;, : double funa( a, b, c) ; / * * / : funa( double a, int b, float c) ; / * * / int char, : 4. 1 double funa( int b, float c, double a) ; / * * / { float add( float x, float y) ; / * add * / float a, b, c; scanf( % f, % f, &a, &b) ; c = add( a, b) ; printf( sum is: % f \n, c) ; float add( float x, float y) /* add * / { float z; ; z = x + y; return( z) ; : 2. 0, 3. 0 : sum is: :,,,, ; 4. 2 float add( float x, float y) /* add * / { float z;
138 z = x + y; return( z) ; void / main( * add ) * / { float a, b, c; scanf( % f, % f, &a, &b) ; c = add( a, b) ; printf( sum is: % f \n, c) ; ,, C,, C : ( ) ;,, :,, C, :,, C,, :,,, C,,,,, Turbo C MS C :, 125
139 126,,,,, return,,,, { float first, second, middle, third, result; float maxf( float num1, float num2) ; /* * / scanf( " % f, % f, % f", &first, &second, &third) ; middle = maxf( first, second) ; / * * / result = maxf( middle, third) ; / * * / printf( " The max is: % f", result) ; float maxf( float x, float y) / * * / { float z; z = x > y? x: y; return z; : 3. 0, 2. 0, 1. 0 : The max is: main( ) 3, maxf( ) : 1, 2, 2 result , ( 1) : n, prime n, n, reverse, prime, reverse( n), n, n ( 2) prime( ), 0, 1 : : prime( a) / * prime a * / b, k; if( a = 2) then 1 ; else if( a 2 ) then
140 else 0 ; { b 1, k 3 while( k < = a b = 1) if( a k ) then b 0 b; k k + 2 ( 3) reverse( int a) a, : a% 10 a, a = a /10,, a = 0 : , = ( ( ( 5* ) * ) * ) * : : reverse( a) / * * / s 0 ; while( a 0) s; s s + a% 10 a a /10 if( a 0) then s s* 10 ( 4) : #include < math. h > { int reverse( int a) ; /* * / int prime( int a) ; /* * / int n; for( n = 11; n < = 99; n + + ) if( prime( n) &&prime( reverse( n) ) ) / * * / printf( 4% d, n) ; int prime( int a) / * * / { int b, k; if( a = = 2) 127
141 128 return 1; else if( a% 2 = = 0) return 0; else { b = 1; k = 3; while( k < = sqrt( 1. 0* a) &&b) { if( a% k = = 0) b = 0; k + = 2; return( b) ; int reverse( int a) / * * / { int s = 0; while( a! = 0) { s = s + a% 10 ; a = a /10; if( a) s = s* 10 ; return s; : , C,, 2 :,,, ( ) ( )
142 ,,,, 4. 5 { int a = 3, b = 5; void swap( int x, int y) ; swap( a, b) ; printf( a = % d, b = % d \n, a, b) ; void swap( int x, int y) { int temp; temp = x, x = y, y = temp; printf( " x = % d, y = % d", x, y) ; : x = 5, y = 3 a = 3, b = 5; swap 2, 2 x y, main ( ) 2 a b, float add( float x, float y) /* add * / { float z; z = x + y; x = x + y; /* x * / printf( " x = % f\ n", x) ; return z; /* add * / { float a, b, c;
143 scanf( " % f, % f", &a, &b) ; c = add( a, b) ; printf( " a = % f\ n", a) ; printf( " sum is: % f \n", c) ;, : 5. 0, 5. 0 : x = add x ; a = a x ; sum is: ,,,,,,, 4. 3 C, C, C C, 4. 4 f1, f1 f2 ; f2, f1 f2 C ; f1, 4. 7 s = 1k + 2k + 3 k + + Nk ( 1) : 2 :, f1( ) n k, n k f2( ) n k,
144 4. 4 ( 2) C : long f1( int n, int k) / * n k * / { long power = n; int i; for( i = 1 ; i < k; i + + ) power * = n; return power; 131 long f2( int n, int k) / * 1 n k * / { long sum = 0; int i; for( i = 1 ; i < = n; i + + ) sum + = f1( i, k) ; return sum; { int n, k; scanf( % d, % d, &n, &k) ; printf( " Sum of % d powers of integers from 1 to % d = ", k, n) ; printf( " % d \n", f2( n, k) ) ; : 4, 5 : Sum of 5 powers of integers from 1 to 4 = 1300, main( ) f2( ), f2 ( ) f1 ( ), 4. 8 e( x), e x (,
145 10-6 ) 132 e x 1 + x + x2 2! + x3 3! + + xn n! ( 1 ) : ; 2 : powers( ) x, n, x n ; fac( ) n, n! ; sum( ) x, e x ( 2) C : #include < math. h > { double sum( float x) ; float x; scanf( " % f", &x) ; printf( " % f powers of e = % lf\ n", x, sum( x) ) ; double sum( float x) { double powers( float x, int n) ; double fac( int n) ; int i = 0; double s = 0; while( fabs( powers( x, i) / fac( i) ) > ) { s = s + powers( x, i) / fac( i) ; i + + ; return s; double powers( float x, int n) { double p = 1. 0; int i; for( i = 1 ; i < = n; i + + ) p* = x; return p; double fac( int n) { int i; double f = 1. 0; for( i = 1 ; i < = n; i + + )
146 f* = i; return f; : 0. 5 : powers of e = : : powers of e = main( ) sum( ), sum( ) fac( ) powers( ), fac( ) powers( ) double, n! x n 4. 9 x 5 - x 4 + 4x 2-1 = ( 1) : 4. 5 x 1 x 2, f( x 1 ) f( x 2 ), ( x 1, x 2 ), f( x 1 ) f( x 2 ), x 1, x 2, f( x 1 ), f( x 2 ) x 1, x 2, ( x 1, x 2 ) f( x 1 ) f( x 2 ), X x, 4. 5 x, x f( x) x = x 1 f( x 2 ) - x 2 f( x 1 ) f( x 2 ) - f( x 1 ) f( x) f( x 1 ), ( x, x 2 ), x x 1 f( x) f( x 2 ), ( x 1, x), x x 2, f( x) <,, 10-6, f( x), : f( x), x 3 - x 4 + 4x 2-1 xpoint( x1, x2), f( x1) f( x2 ) x x
147 134 root( x1, x2 ), ( x1, x2) root xpoint, xpoint f ( 2) : : root( x1, x2) x, y, y1; y1 f( x1) while( ) x xpoint( x1, x2) / * x; * / y f( x) if( y* y1 > 0) then x1 x, y1 y else x2 x x; ( 3) : #include < math. h > float f( float x) { float y; y = x* x* x* x* x - x* x* x* x + 4* x* x - 1; return y; float xpoint( float x1, float x2) { float x; x = ( x1* f( x2) - x2* f( x1) ) / ( f( x2 ) - f( x1) ) ; return x; float root( float x1, float x2) { float x, y, y1; y1 = f( x1) ; do { x = xpoint( x1, x2) ; y = f( x) ; if( y* y1 > 0) { y1 = y; x1 = x; else x2 = x;
148 while( fabs( y) > = ) ; return x; { float x1, x2, f1, f2, x; do { printf( input x1, x2: \n ) ; scanf( % f, % f, &x1, &x2) ; f1 = f( x1) ; f2 = f( x2) ; while( f1* f2 > = 0) ; x = root( x1, x2) ; printf( " The root of equation is % 8. 4f", x) ; : Input x1, x2: 0, 1. 0 : The root of equation is : Input x1, x2: , 0 : The root of equation is ,,,,,,, : ;, ;, ( ), ;,,,,,,,,
149 { void reverse( ) ; reverse( ) ; void reverse( ) { char ch;, ch = getchar( ) ; if( ch = = # ) else printf( " % c", ch) ; { reverse( ) ; : abcdef# printf( " % c", ch) ; : #fedcba ( FILO),, 4. 10, abcdef,, printf( " : % c", ch), a f #,, #,, f a ( 1) : n! : n! = n* ( n - 1)! ( n > 1) : n! = 1 ( n = 0, 1) ( 2) : : fac( n) if( n = 0 n = 1) else 1 ; then fac( n - 1) * n ( 3) C : { long fac( long n) ;
150 long i, result; scanf( " % ld", &i) ; result = fac( i) ; printf( " % ld! = % ld \ n", i, result) ; long fac( long n) { if( n < = 1 ) return 1; else return fac( n - 1) * n; : 4 : 4! = 24 i 4, 4! 4 * 3!, 3!, 3! 3* 2!, 2!,,, 1! = 1,, 1!, 2!, 3!, 4!, : ( 1) : f( n) k if( n = 0 n = 1) then else k 1 k f( n - 1) + f( n - 2) k ( 2) C : 4. 6 f( n) = 1 n = 0 n = 1 f( n - 1) + f( n - 2) n > 1
151 138 { int n; float f( int i) ; / * * / printf( " Input n: " ) ; scanf( " % d", &n) ; / * n* / printf( " \nf( % d) = % f", n, f( n) ) ; float f( int i) { float k; if( i = = 0 i = = 1) / * * / else k = 1; k = f( i - 1) + f( i - 2) ; / * * / return k; : Input in : 12 : f( 12) = , 2, 2,,,, ( Tower of Hanoi) A B C3, A 64 A B,,, 64 : 2 64 A) ; B* / ( 1) : - 1 = 18, 466, 744, 073, 709, 511, : n - 1 B C, hanoi( n - 1, A, C, B) ; 2 : n A B ; 3 : C n - 1 A B, hanoi( n - 1, C, B, ( 2) : : Hanoi( n, A, B, C) / * Hanoi A n C if( n = 1) then else A-> B ; / * n = 1 * / Hanoi( n - 1, A, C, B) / * A n - 1 B C* / A-> B ; / * A B; * /
152 Hanoi( n - 1, C, B, A) / * C n - 1 A B* / ( 3) C : { int n; void hanoi( int n, char a, char b, char c) ; printf( " \nplease input the number of disks to be moved: " ) ; scanf( " % d", &n) ; hanoi( n, a, b, c ) ; void hanoi( int n, char a, char b, char c) { if( n > 0 ) { hanoi( n - 1, a, c, b) ; printf( " \nmove disc % d from pile % c to % c", n, a, b) ; hanoi( n - 1, c, b, a) ; : Please input the number of disks to be moved: 3 : Move disc 1 rom pile a to b Move disc 2 from pile a to c Move disc 1 from pile b to c Move disc 3 from pile a to b Move disc 1 from pile c to a Move disc 2 from pile c to b Move disc 1 from pile a to b,,,,,,,,, C C C,, C,, #,,
153 ; C, 3 : C, #define, 1 ) 140 : #define,,, ( ),, #define PI #define R 2. 0 { double circum( ) ; double area( ) ; circum( ) ; area( ) ; printf( " Circum = % f, Area = % f\ n", circum( ), area( ) ) ; double circum( ) { return( 2. 0 * PI* R) ; double area( ) { return( PI* R* R) ; circum( ) area ( ), : double circum( )
154 { return( 2. 0 * * 2. 0) ; double area( ) { return( * 2. 0* 2. 0) ; :? Circum = , Area = ,, 4, : # define R 4. 0,,,,,, #define EOF - 1 / * * / #define NULL 0 / * * / #define MIN 1 / * * / #define MAX 31 / * * / #define STEP 2 / * * / #define PI / * * / #undef, : #undef R R ) C, : #define ( ) : ( ) :,, #define PI #define S( r) ( PI* ( r) * ( r) ) { float a, b, area1, area2; a = 3. 3; b = 3. 2;
155 area1 = S( a) ; area2 = S( a + b) ; printf( " area1 = % f, area2 = % f \n", area1, area2) ; : area1 = , area2 = , area1 = S( a), area2 = S( a + b ) : area1 = * 3. 3* 3. 3, area2 = * ( ) * ( ) :, #define SQ1( x) x* x #define SQ2( x) ( x) * ( x) #define SQ3( x) ( ( x) * ( x) ) { printf( % f, % f, % f, 1. 0 / SQ1 ( ), 1. 0 / SQ2 ( ), 1. 0 / SQ3( ) ) ; : , , x,, 3 : 1. 0 / SQ1( ) 1. 0 / * ( ) 1. 0 / SQ2( ) 1. 0 / ( ) * ( ) ( ) 1. 0 / SQ2( ) 1. 0 / ( ( ) * ( ) )( ) 3 ), :,, :,,,,, ;,,,
156 : #include < > #include,, ;,, C : 1 ) math. h,,, ( 1) int abs( int x) ; double fabs( double x) ; / * x * / double floor( double x) ; / * x * / double fmod( double x, double y) ; / * x/ y * / double pow( double x, double y) ; / * x y * / double sqrt( double x) ; / * x * / ( 2) double sin( double x) ; double cos( double x) ; double tan( double x) ; double exp( double x) ; double log( double x) ; ( 3) ( stdlib. h ) int rand( void) ; int rand( int seed) ; /* * / /* seek ( ) * /,,,, 143
157 2 ) ctype. h,,,, int int isalpha( int ch) ; / * ch, 1, 0 * / int isdigit( int ch) ; / * ch ( 0 9), 1, 0 * / int iscntrl( int ch) ; / * ch, 1, 0 * / int isprint( int ch) ; / * ch, 1, 0 * / int tolower( int ch) ; / * ch * / int toupper( int ch) ; ch * / 3 ) 144 string. h,,, strlen( ) : int strlen( const char * s) ; s,, strcpy( ), : char * strcpy( char * s1, const char * s2) ;, s1 s2, s2 s1 s1, : s1 s2, strcat( ), : char * strcat( char * s1, char * s2) ;, s1 s2, s1,, s1 s2, s1 strlen( s1 ) + strlen( s2) + 1 strcmp( ), 0, ; 0, ; 0, : int strcmp( const char * s1, const char * s2 ) ; int strncmp( const char * s1, const char * s2, int n) ; strcmp( ), strncmp( ) s1 s2 n
158 ,, 6 C,,,,, C,, C,, C, ( 1) #include C, C C #include " ex4_17b. cpp" { long fac( long n) ; long i, result; scanf( " % ld", &i) ; result = fac( i) ; printf( " % ld! = % ld \ n", i, result) ; / * ex4 _17b. c* / long fac( long n) { if( n < = 1 ) return( 1) ; else return( fac( n - 1) * n) ;, C ex4-17a. cpp ex4-17b. cpp, ex4-17a. cpp #include ex4-17 b. cpp ex4-17b. cpp ex4-17 a. cpp : ex4-17a. cpp ex4-17b. cpp,, : myfile. h, ( ),, : 145
159 146 #include < myfile. h > ( 2) C C Turbo C IDE, Turbo C IDE : Project( ) ; Project Open Project( ) ; ( ) ; ( ), OK Project: < > ; Project, Add Item Add to Project List ; Add to Project List C, Add ; 5,,, C C ex4-17a. cpp ex4-17b. cpp, ex4-17. prj Project( ) ; Project Open Project( ) ; ex4-16;, OK Project: ex4-17. prj ; Project, Add Item Add to Project List ; Add to Project List ex4-17a. cpp, Add ; ex4-17b. cpp, Add C,, : ( 1) #if < 1 > < 1 > #elif< 2 > < 2 >
160 #elif< n > #else #endif < n > < > : 0 ( ),, 4. 19,,,, #, LETTER #include stdio. h #define LETTER 1 { unsigned char ch; 2 while( 1) { ch = getchar( ) ; if( ch = = # ) break; #if LETTER if( ch > = a &&ch < = z ) ch - = 32; #else if( ch > = A &&ch < = Z ) ch + = 32; #endif putchar( ch) ; : afaffas# : AFAFFAS ( 2) #ifdef #else #endif : #define, 1, #ifdef 147
161 148, TRANS #define, #define TRANS { char ch; while( 1) { ch = getchar( ) ; if( ch = = # ) break; #ifdef TRANS if( ch > = a &&ch < = z ) ch - = 32; #else if( ch > = A &&ch < = Z ) ch + = 32; #endif putchar( ch) ; ( 3) #ifndef #else #endif 1 2 #ifdef #endif, #ifndef, TRANS #define, #define TRANS { char ch; while( 1) { ch = getchar( ) ; if( ch = = # ) break; #ifndef TRANS
162 if( ch > = a &&ch < = z ) ch - = 32; #else if( ch > = A &&ch < = Z ) ch + = 32; #endif putchar( ch) ; : ASDAF# : asdaf 4. 6 C C, C, C, C : C main ( ) C, ( ) (, goto ), : ( ) ; ( ) ; , C,,, ;, 3 :,,, 2,,,,,
163 150, 2,,,,,,,,,,,,, ;,, C, : ; ; : ( auto) ( register) ( static) ( extern) C,, : auto auto, auto, auto,,, ;,, 3 : ; ; :, ;, 4. 22
164 { int x = 1; { void print( ) ; int x = 3; print( ) ; printf( " 2ND x = % d \n", x) ; printf( " 1ST x = % d \n", x) ; void print( ) { int x = 5; printf( " 3TH x = % d \ n", x) ; : 3 TH x = 5 2 ND x = 3 1 ST x = 1, 3 x, main( ) print( ) x, ;, main( ) x, x x { int sum( int j) ; int j, s; for( j = 1 ; j < = 10; j + + ) s = sum( j) ; printf( " s = % d \n", s) ; int sum( int j) { int x = 0; x + = j; return( x) ; : s = 10( s = 55),,, 151
165 ,, CPU : register : register ;, register, register :,,,, C,,, ,,,, C, static,, : satic ; :,,,, 0 ( ) 0. 0 ( ) ( ),
166 , int fauto( ) { int j = 0; / * fstatic j * / j + + ; return j; int fstatic( ) { static int j = 0; / * fauto j * / * / j + + ; return j; { printf( " % d, % d \ n", fauto( ), fauto( ) ) ; printf( " % d, % d \ n", fstatic( ), fstatic ( ) ) ; : 1, 1 2, long fac( int n) { static long f = 1; f = f* n; return f; { int k; for( k = 1; k < = 5 ; k + + ) printf( % d! : 1! = 1 2! = 2 3! = 6 4! = 24 5! = 120 = % ld \ n, k, fac( k) ) ; / * printf 153
167 C,,,, ;,, : extern, extern int j = 1; { void add( ) ; add( ) ; j + + ; printf( " j = % d \ n", j) ; void add( ) { j + + ; : j = 3, 2, return, x, y float sum, ave; / * * / { int x, y; void f( int x, int y) ; / *, * / scanf( " % d, % d", &x, &y) ; / * * / f( x, y) ; / * * / printf( " sum = %. 2f\ n ave = %. 2f \n", sum, ave) ; void f( int x, int y) { sum = x + y; / * x, y, sum * / ave = ( x + y) /2. 0 ; / * x, y, ave * /
168 : 2, 3 : sum = ave = 2. 50,, :,,,,,,,,,,,, :, ( ), extern int j = 1; { void add( ) ; add( ) ; j + + ; printf( " j = % d \ n", j) ; void add( ) { int j = 0; j + + ; add ( ) j, add( ) j, : j = 2 extern,, extern extern, 155
169 156 { extern int a, b; / * a, b, int max( int x, int y) ; * / printf( " max = % d \n", max( a, b) ) ; int a = 5, b = 8; int max( int x, int y) { int z; z = x > y? x: y; return( z) ; : max = 8 / * a, b, * / extern C,, extern, extern / * ex4 _30A. cpp* / int x, y; / * x, y, ch* / char ch; { extern void fun1( ) ; / * fun1, fun2 * / extern void fun2( ) ; ch = a ; x = 10; y = 4; fun1 ( ) ; fun2 ( ) ; printf( " x = % d, y = % d \n", x, y) ; printf( " ch = % c \ n", ch) ; / * ex4-30b. cpp * / extern int x, y; / * x, y * / void fun1 ( ) { y + = 1; x = ( + + x + 4) % y;
170 / * ex4-30c. cpp * / extern char ch; / * ch * / void fun2 ( ) { printf( " ch = % c in file ex4-30 c. cpp \n", ch + + ) ; ch + + ; ex4-30 a. exe : ch = a in file ex4-30c x = 0, y = 5 ch = c,, extern, static / * ex4 _31A. cpp* / int x, y; /* x, y* / static char ch; / * ch, * / { extern void fun1( ) ; /* fun1, fun2 * / extern void fun2( ) ; ch = a ; x = 10; y = 4; fun1 ( ) ; fun2 ( ) ; printf( " x = % d, y = % d \n", x, y) ; printf( " ch = % c \ n", ch) ; / * ex4-31b. cpp * / extern int x, y; /* x, y * / void fun1 ( ) { y + = 1; x = ( + + x + 4) % y; 157
171 / * ex4-31c. cpp * / extern char ch; /* ch, * / void fun2 ( ) /* ch * / { printf( " ch = % c in file ex4-31 c. cpp \n", ch + + ) ; ch + + ; 3 C, ex4-31. prj, ex4-31prj : undefined symbol _ch in module ex4-31 c. cpp( ex4-31. cpp ch) ( ) ( ) 158 CPU ( ) , C,,,,,,, static, : static ( ) { static,, static, :,,
172 :, static, extern, : [ extern] ( ) {, : [ extern] ( ) ; ( 1) mainf. c main( ) { extern void input( ), process( ), output( ) ; input( ) ; process( ) ; output( ) ; ( 2) subf1. c extern void input( ) / * * / { ( 3) subf2. c extern void process( ) / * * / { ( 4) subf3. c extern void output( ) / * * / { , void main ( ) { int x, n, s; power( y) { int i, p = 1; for( i = 0; i < = n; + + i) p = p* y; ; 4. 2 ( 1) C, ( ) A. C,,,
173 160 B. C, C., D. C ( 2) C, ( ) A. auto B. static C. extern D. ( 3), ( ) A., B., C., D., ( 4) ( ) A. x = 1 y = 1 x = 1 y = 1 B. x = 1 y = 1 x = 2 y = 2 C. x = 1 y = 1 x = 2 y = 1 D. x = 1 y = 1 x = 1 y = 2 : { void f1( ) ; void f2( ) ; f1( ) ; f2( ) ; f1( ) ; f2( ) ; void f1( ) { int x = 0; printf( " x = % d \t", + + x) ; void f2( ) { static int y = 0; printf( " y = % d \t", + + y) ; ( 5) ( ) A., B., C. D. 4. 3
174 ( 1) ( 2) : return < > 4. 4 ( 1) int a, b, c, d; { void p( int a, int b) ; a = b = c = d; printf( " % d, % d, % d, % d \n", a, b, c, d) ; p( a, b) ; printf( " % d, % d, % d, % d", a, b, c, d) ; void p( int a, int b) { static int c; a + +, b + + ; c - = 10, d + = 5 ; if( a < 3) p( a, b) ; printf( " % d, % d, % d, % d", a, b, c, d) ; ( 2) float f( int n) { float x; if( n < 0) printf( " n < 0, data error! \ n" ) ; else if( n = = 0 n = = 1) x = 1 else x = f( n - 1 ) * n; return x; { int i, n; float y = 0; printf( " input a integer number: " ) ; scanf( " % d", &n) ; for( i = n; i > = 1; i - - ) y = y + f( i) ; printf( " y = % 5. 1f \n", y) ; 161
175 162 ( 3) / * 1, 1* / #define PI #define S( r) PI* r* r { float a, b, s1, s2 ; printf( " Input the a, b: " ) ; scanf( " % f, % f", &a, &b) ; s1 = S( a) ; s2 = S( a + b) ; printf( " s1 = % f, % s2 = % f\ n", s1, s2) ; ( 4) / * 2005* / { void printd( int n) ; int num; printf( " Input the number" ) ; scanf( " % d", &num) ; printd( num) ; void printd( int n) { if( n < 0) { putchar( - ) ; n = - n; if( n /10) printd( n /10 ) ; putchar( n% ) ; 4. 4 n n : 4, 13, 15, 17, = Hermite, Hn( x) : H 0 ( x) = 1 n = 0 H 1 ( x) = 2x n = 1 H n ( x) = 2xH n - 1 ( x) - 2 ( n - 1 ) H n - 2 ( x) n > (,,
176 , 25, 25 2 = 625, , 25 ) 4. 7 kkkkk kk( n k, n k ), : Sn = a + aa + aaa + + aaaa aa( n a) (, n = 4, k = 3, : s = ) 163
177 164 C ; ;, C, C, C ,? 1 1,, 16 2, 1,,,,,,
178 ,, C, : scanf,,,,,, 5. 1 : 5. 1 *, ; :, auto register static extern ;,, ;, : int * ptr; / * ptr* / char * ch; /* ch* / :, ( * ),, ptr * ptr, : : * = ; int count = 18, * ptr = &count;, *, : int * ptr1, ptr2; ptr1 ptr2 2, : int * ptr1, * ptr2; 165
179 ) 166,,,,, C,,,, C &, &,, &x x ptr, a ptr 2 : ( 1) int a; int * ptr = &a; /* a ptr* / ( 2) int a; int * ptr; ptr = &a;, : int * p; p = 1000; /* * / *, * p = &a : int a; char * ptr; ptr = &a; /*, * / : int i, * ptr; i = 20; ptr = &i;
180 5. 2 & ptr i, ptr i ) * * ( ),, : int x = 20, y, * ptr; ptr = &x; y = * ptr; : x( 20 ) y ptr, x ptr, ptr, y, y = x;, , * : printf( % d, * i) ; / * error, * / : *, ( &) &,,,
181 3 ) p, n, p + n p - n n, n,, 16 char 1 int 2 long float 4 double 8, : ,,,, n, ptr1, 3000, 2, ptr ++ ; ptr += 1; ptr ptr, ptr - - ptr 2998, ,, ptr = ptr + n; ptr n 2 2, 5. 1 { int a = 1, b = 2, c = 3, * ptr; ptr = &b; printf( " b: Address % x, Value % d \ n", ptr, b) ; ptr ++ ; printf( " c: Address % x, Value % d \ n", ptr, c) ; ptr - = 2;
182 ) : printf( " a: Address % x, Value % d \ n", ptr, a) ;, ( b: Address fff2, Value 2 c: Address fff4, Value 3 a: Address fff0, Value 1 : 3 a b c, ptr b, b fff2; 1, 1 * 2 = 2, ptr c, fff4; ptr - 2, ptr a, fff0 :,, 5. 2 { int i = 20; int * iptr = &i; printf( " i: value % d \ n", * iptr) ; printf( " i address: % d \n", iptr) ; printf( " iptr address: % d \ n", &iptr) ;,, * iptr iptr &iptr, : i value: 20 i address: 6630 iptr address: { int a = 1, b = 2, * aptr, * bptr; aptr = &a; bptr = &b; printf( " a: Address % x; b: Address % x \n", aptr, bptr) ; printf( " aptr > bptr = % d \n", aptr > bptr) ; printf( " aptr < = bptr = % d \ n", aptr < = bptr) ; 169
183 170 printf( " aptr&&bptr = % d \ n", aptr&&bptr) ;, : a: Address fff4, b: Address fff2 aptr > bptr = 1 aptr < = bptr = 0 aptr&&bptr = 1,, :, 2, : 2 ptra ptrb, ptra + ptrb,, : Null point assigment,, { int a = 1, b = 2, * aptr = &a, * bptr = &b; printf( " * ptra: Value % d \ t* ptrb: Value % d \n", * aptr, * bptr) ; bptr = aptr; printf( " * ptra: Value % d \ t* ptrb: Value % d \n", * aptr, * bptr) ; bptr = aptr bptr aptr ( a) : 5. 5 * ptra: Value 1 * ptrb: Value 2 * ptra: Value 1 * ptrb: Value 1 2 { int a = 1, b = 2, * aptr = &a, * bptr = &b, * tptr; printf( " * ptra: Value % d \ t* ptrb: Value % d \n", * aptr, * bptr) ; tptr = aptr, aptr = bptr, bptr = tptr; printf( " * ptra: Value % d \ t* ptrb: Value % d \n", * aptr, * bptr) ; 3 tptr = aptr = bptr = tptr aptr bptr, 2 :
184 5. 6 * ptra: Value 1 * ptrb: Value 2 * ptra: Value 2 * ptrb: Value 1 2 { int a = 1, b = 2, temp, * aptr = &a, * bptr = &b; printf( " a: Value % d \tb: Value % d \n", a, b) ; temp =* aptr, * aptr =* bptr, * bptr = temp; printf( " a: Value % d \tb: Value % d \n", a, b) ; 3 temp =* aptr * aptr =* bptr * bptr = temp a( * ptra) b( * ptrb), 2 : 5. 7 a: Value 1 b: Value 2 a: Value 2 b: Value 1 { int a = 20 ; int * aptr; aptr = &a; printf( " a: Value % d \n ", a) ; * aptr = 30; printf( " after changed a: Value % d ", a) ; * aptr = 30 a, a = 30, : 5. 8 a: Value 20 after changed a: Value 30 x y, z 3, ( ) ( 1) : 3 2, 3 3 ( 2) : : x, y, z pmax, pmin x, y, z if( x > y) then 171
185 172 : pmax = &x; : pmin = &y; else : pmax = &y; : pmin = &x; if( z >* pmax) then pmax = &z; if( z <* pmin) then pmin = &z; : * pmax, * pmin ( 3) : { int x, y, z, * pmax, * pmin; printf( " Input three numbers: \ n" ) ; scanf( " % d% d% d", &x, &y, &z) ; if( x > y) { pmax = &x; pmin = &y; else { pmax = &y; pmin = &x; if( z >* pmax) pmax = &z; if( z <* pmin) pmin = &z; printf( " max = % d \nmin = % d \n", * pmax, * pmin) ;
186 ,,,, , ( 1) : 2 swap 2 2,, 2 ( 2) : void wap( int x, int y) ; { int a, b; printf( " Input a, b: \ n" ) ; scanf( " % d% d", &a, &b) ; printf( " a = % d, \ tb = % d \ n", a, b) ; if( a < b) swap( a, b) ; printf( " after swap: \n" ) ; printf( " a = % d, \ tb = % d, \n", a, b) ; void wap( int x, int y) { int temp; temp = x; / * 2 * / x = y; y = temp; printf( " In function swap: x = % d, \ty = % d, \ ttemp = % d \n", x, y, temp) ; 173
187 174, : Input a, b: 7 10( ) a = 7, b = 10 In function swap: x = 10, y = 7, temp = 7 after swap: a = 7, b = 10,, swap x y main a b 5. 5 ( 3) : 5. 5 { void swap( int * ptr1, int * ptr2) ; int a, b, * p1, * p2; printf( " Input a, b: " ) ; scanf( " % d% d", &a, &b) ; printf( " a = % d, \ tb = % d \ n", a, b) ; p1 = &a; p2 = &b; if( a < b) swap( p1, p2 ) ; printf( " after swap: \n" ) ; printf( " a = % d, \ tb = % d \ n", a, b) ; void swap( int * ptr1, int * ptr2) { int temp; temp =* ptr1; * ptr1 =* ptr2; * ptr2 = temp; input a, b: 7 10( ) a = 7, b = 10 after swap: a = 10, b = 7 :, void swap( int * ptr1, int * ptr2) ;
188 , swap( p1, p2) ;, 2 5 swap( p1, p2 ), swap * ptr1 * ptr2 main a b temp, a b, a b, swap a b { int add( int * ptr1, int * ptr2) ; int x1, x2, y; printf( " Input x1, x2: " ) ; scanf( " % d, % d", &x1, &x2) ; y = add( &x1, &x2) ; 5. 6 printf( " y = x1 + y2 = % d \ n", y) ; int add( int * ptr1, int * ptr2) { int z; z =* ptr1 +* ptr2; return z; 5. 10, add 2, 2 int add, x1 x2 &x1 &x2 ptr1 ptr2, ptr1 ptr2 x1 x2, * ptr1 * ptr2 x1 x2, * ptr1 +* ptr2 x1 + x2 :, : int x, * ptr; ptr = &x;, ptr, x : 5. 11
189 176 { void swap( int * ptr1, int * ptr2) ; int x, y, * ptr1, * ptr2; printf( " Input x, y: " ) ; scanf( " % d% d", &x, &y) ; printf( " before swap: % d \ t% d \ n", x, y) ; ptr1 = &x; ptr2 = &y; if( x < y) swap( ptr1, ptr2) ; printf( " after swap: % d \ t% d \ n", x, y) ; void swap( int * ptr1, int * ptr2) { int * temp; temp = ptr1; ptr1 = ptr2; ptr2 = temp; printf( " in swap: % d \t% d \ n", * ptr1, * ptr2) ;, x y &x &y, ptr1 ptr2 x y x y, ptr1 ptr2,,, 2, : Input x, y: 30, 100( ) before swap: in swap: after swap: , C,,,,,, float fun( ), fun,,
190 ,, ( ) : ( * ) ( ) ;, ; : int ( * function) ( ) ; ( ) function,, , : : void swap( int * ptr1, int * ptr2 ) ; : void ( * fptr) ( int * ptr1, int * ptr2) ; swap fptr : fptr = swap; ( ), n, n, : / / /n 2 n, : / / /n 2 ( 1) : ptr / * ptr * / n if( n > 1) then if( n ) then ptr fun1 else ptr fun2 else 177
191 178 ( 2) : double func1( int x), func2( int y) ; { double ( * fptr) ( int) ; / * fptr* / int n; printf( " Input a number: " ) ; scanf( " % d", &n) ; if( n > 1 ) { if( n% 2 == 0) fptr = func1; / * n, ptr func1( ) * / else fptr = func2; / * n, ptr func2( ) * / printf( " value = % 9. 4f\ n", ( * fptr) ( n) ) ; else printf( " error! \ n" ) ; double func1( int x) { int k; double value; value = 1. 0; for( k = 2; k < = x; k = k + 2) value = value + ( 1 / ( double) k) * ( 1 /( double) k) ; return value; double func2( int y) { int k; double value; value = 1. 0; for( k = 3; k < = y; k = k + 2) value = value + ( 1 / ( double) k) * ( 1 /( double) k) ; return value; main, fptr, :
192 ,, fptr = func1; ( * fptr) ( n), : fptr = func1; fptr = func2; fptr : fptr = func1 ; fptr = func2;, : fptr, fptr = fptr + 1 fptr = fptr C,,,, ( ) f 1 ( x) = 1 + x 2 [ 0, 1] f 2 ( x) = 1 / ( x 2 ) [ - 1, 1] ( 1) : 2,, double, x, float : double collect( double ( * p) ( float x), float a, float b, int n) 4, p, double a, b, n, 2 collect n ( 2) : { int n; double y1, y2; double fun1( float x) ; double fun2( float x) ; double collect( double ( * p) ( float x), float a, float b, int n) ; y1 = collect( fun1, 0. 0, 1. 0, 200) ; y2 = collect( fun2, 0. 0, 2. 0, 200) ; printf( " y1 = % f \ny2 = % f\ n", y1, y2) ; double collect( double ( * p) ( float x), float a, float b, int n) 179
193 180 { int i; float f, h, area; h = ( b - a) / n; area = ( ( * p) ( a) + ( * p) ( b) ) /2. 0; for( i = 1 ; i < n; i ++ ) area += ( * p) ( a + i* h) ; return area* h; double fun1( float x) / * 1 + x 2 C * / { float f; f = 1 + x* x; return f; double fun2( float x) / * 1 / ( x 2 ) C * / { float f; f = 1 /( * x* x) ; return f; 5. 4,, ( void), C ( ), : * ( ) ;, : float * funcname( float x, float y) : float funcname, funcname, float * funcname( float x, float y) float * ptr ptr *, * ptr,, funcname *,, * x y
194 C, ( ), malloc malloc stdlib. h alloc. h, #include : void * malloc( unsigned size) ; : C ( ) size, ( ),, NULL, free free stdlib. h alloc. h, : void free( void * ptr) ; ptr malloc free #include < stdlib. h > { int * ptr; ptr = ( int * ) malloc( sizeof( int) ) ; if( ptr == NULL) { printf( " Failed to create a new object. " ) ; exit( 0) ; * ptr = 100; printf( " value of * ptr is: % d \ n", * ptr) ; free( ptr) ; malloc, ptr, * ptr, 100 * ptr,, free : C,, :,,
195 182,,, : { int i; char * ptr; i = 200 ; * ptr = i; ptr, ptr, * ptr = i i 200,, : char ch, * ptr1; / * ch ptr1* / double db, * ptr2; / * db ptr2* / ptr1 = &db; ptr2 = &ch; ptr1, db, ptr2, ch, ptr * ptr, * ptr ptr ( 1) char * ptr, a; ( ) A. a = ptr B. ptr = ptr /2 C. ptr = &a D. * p = 20 ( 2), ( ) A. B. C. D. ( 3) char ** pptr; ( ) A. pptr = 100 B. * pptr = " study" C. ** pptr = " study" D. * pptr = study ( 4) int a = 20; int * ptrl, * ptr2; ptrl ptr2 a, ( )
196 A. a = * ptr1 + * ptr2; B. ptr2 = a; C. ptrl = ptr2; D. a = * ptrl* ( * ptr2) ( 5) int ( * ptr) ( ) ; ( ) A. ptr, int B. ptr C. ptr, D. ptr ( 6 ) add( x, y), ptr add, ( ) A. ptr = max B. * ptr = max C. ptr = max( a, b) D. * ptr = max( a, b) ( 7) min( a, b), ptr, ( ) A. ( * ptr) min( a, b) B. * ptr min( a, b) C. ( * ptr) ( a, b) D. * ptr( a, b) ( 8), a b ( ) main( ) { int a, b, k = 4, m = 6, * ptr1 = &k, * ptr2 = &m; a = ptr1 == &m; b = ( * ptr1) / ( * ptr2 ) + * ptr1 ; printf( " a = % d \ n", a) ; printf( " b = % d \ n", b) ; A. 0, 6 B. 1, 6 C. 0, 4 D. 1, 4 ( 9) 2, ( ) main ( ) { void swap( int * p, int * q) ; int a = 10, b = 20; printf( " a = % d, b = % d \ n", a, b) ; swap( &a, &b) ; printf( " a = % d, b = % d \ n", a, b) ; void swap( int * p, int * q) { int * t; 183
197 184 t = p; p = q; q = t; A. B., swap( &a, &b) ; a, b C., swap ( ) p q t ( ) D. ( 10), ( ) main( ) { int * iptr, i; char * qptr, ch; iptr = &i; qptr = &ch; * iptr = 40; * iptr =* qptr; A. iptr qptr, * p =* q B. * iptr, * iptr = 40; C. qptr, * qptr D. qptr,, * iptr =* qptr; ( 11) char * ptr; char ch; ptr = &ch; ( ) A. ch, ptr, * &a B. ch, &ch, * ptr C. * &ptr, * ptr, &ch D. &ch, &* ptr, ptr 5. 2 ( 1 ) : char * func1 ( ) ; char ( * func2 ) ( ) ; ( 2) C, ( 3) main( ) { int * ptr; ptr = 200; ( 4)
198 main( ) { int ** ptr1, * ptr2, a = 20 ; ptr2 = &a; ptr1 = &ptr2; printf( " % d \ n", ** ptr1) ; ( 5) main( ) { int * ptr, a; a = 20; ptr = &a; a = * ptr + 10; printf( " % d \ n", a) ; ( 6) sub( int * s) ; main( ) { int i, k ; for( i = 0; i < 4; i ++ ) { k = sub( &i) ; printf( " % 3d", k) ; printf( " \ n" ) ; sub( int * s) { static int t = 0; t = * s + t ; return t; ( 7) #include " stdio. h" int func( int x, int y, int * cp, int * dp) ; main( ) { int a, b, c, d; 185
199 186 a = 4; b = 3 ; func( a, b, &c, &d) ; printf( " % d \ n", c + d) ; func( int x, int y, int * cp, int * dp) { * cp = x + y; * dp = x - y; return 1; 5. 3 ( 1)? ( 2)? ( 3)? 5. 4 ( 1) pa pb, int a int b pa pb : a b ; (, 0 ) ;, pa, pb ( 2) 3 a, b, c, ( ) ( 3) 3, ( 4) f 1 ( x) = 1 + x + 1 / x 2 ( 1, 2] ( 5), 2 ( 6) 1 n, n, : /2 + 1 / / n n, : /3 + 1 / / n
200 ,,, C,,,, ( ), : array_int word_arr T h e w o r d - f o r m a t i o n ,
201 188, Turbo C , 2, 1, 0,, : [ ] ;,,, C,,,,,, word _arr 100, int array_int[ 10] ; / * array_int, 10 * / float b[ 10], c[ 20] ; / * b, c; * / char word_arr[ 100] ; / * word_arr, 100 * / :,,,, 2 :, ;,,,, C 0, : #define FD 50 { int a[ FD + 5], b[ FD] ; { : int n = 5; int a[ n] ; ( ), int a, b, c, d, k1 [ 10], k2[ 20] ;
202 ( auto), ( static) ( extern) : static float score[ 50] ; : 10 #define arrlen 10 { int i, a[ arrlen] ; for( i = 0 ; i < arrlen; ) a[ i + + ] = 2* i + 1; i = 5; printf( " \ninput a[ % d] ", i + 2) ; scanf( " % d", &a[ i + 2 ] ) ; printf( " \noutput the list: \n" ) ; for( i = 0 ; i < = arrlen - 1; i + + ) printf( " a[ % d] \ t", i) ; for( i = 0 ; i < = arrlen - 1; i + + ) printf( " % d \ t", a[ i] ) ; printf( " \noutput the reverse list: \ n" ) ; for( i = arrlen - 1; i > = 0; i - - ) printf( " % d \ t", a[ i] ) ; printf( " \na[ 5. 2] = % d a[ 5. 8 ] = % d \ n", a[ 5. 2], a[ 5. 8] ) ; arrlen, 10,, a for, 3 i + +,, i, i = 5; scanf( ), a[ i + 2], 2 for, 3 for 4 for printf a[ 5 ], : [ ]
203 ,, i = 4, a [ 5 ], a [ i], a [ i + 2] 3 a[ i], a [ 5], a[ i + 2 ] C,, : int a[ 10 ] ; a[ 10] = 100; a = 100;,,, : ( 1) 190 int arr[ 20] ; for( i = 0; i < 20; i + + ) / * * / scanf( % d, &arr[ i] ) ; for( i = 0; i < 20; i + + ) / * 2340* / arr[ i] = 2340; arr[ 2] = ( ) / ( 37* 23) ; / * * / ( 2) for( i = 0; i < 20; i + + ) printf( " % d \n", a[ i] ) ;,, C,, : 6. 2 int a[ 10 ] ; for( i = 0; i < = 20; i + + ) scanf( % d, &a[ i] ) ; ( 1) : i, j; 10 ; i < - 0, j < - 9; while( i < j) i j i + +, j ; ( 2) :
204 { int arr[ 10], i, j, temp; 6. 3 printf( " Input ten value of Array: \ n" ) ; for( i = 0; i < 10; i + + ) scanf( " % d", &arr[ i] ) ; for( i = 0, j = 9; i < = j; i + +, j - - ) temp = arr[ i], arr[ i] = arr[ j], arr[ j] = temp; for( i = 0 ; i < 10; i + + ) printf( " % 4d", arr[ i] ) ; , : ( 1) : , 1 1, n n,,, : yh[ 1] = 1; / * 1 * / row = 2; yh[ row] = 1; / * 2 2, 1* / col = row - 1; / * 2-1 * / row[ col] = yh[ col] + yh[ col - 1] ; / * 2 1 = yh[ 1] + yh[ 0 ] ( yh [ 0] ( 2) : ; row, col; yh[ 1] < - 1 yh[ 1 ] < - 1 row < - 2 while( row < = 10) yh[ row] < - 1 col < - row - 1 while( col > = 2) = 0) * / 191
205 192 yh[ col] < - n yh[ col] + yh[ col - 1] col < - col - 1 col < - 1 while( col < = row) yh[ col] col < - col + 1 row < - row + 1 ( 3) : { int yh[ 11], row, col; yh[ 1 ] = 1; printf( " \n% 4 d \ n", yh[ 1 ] ) ; for( row = 2; row < = 10; row + + ) { yh[ row] = 1; for( col = row - 1; col > = 2; col - - ) yh[ col] = yh[ col] + yh[ col - 1] ; for( col = 1 ; col < = row; col + + ) printf( " % 4d", yh[ col] ) ; printf( " \n" ) ; : [ ] = { ;,, : int a[ 10 ] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ; a[ 0] = 1; a[ 1] = 2, ; a[ 9 ] = 10 : char word_arr[ ] = { T, h, e,, w, o, r, d, -, f, o, r, m, a, t, i, o, n ;,, word_arr 18 : {, : int a[ 10] = {0, 1, 2, 3, 4 ; a[ 0] a[ 4] 5, 5 0
206 , 10 1, : int a[ 10 ] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ; : int a[ 10] = 1;,, 0,,, : int a[ 5] = {1, 2, 3, 4, 5 ; : int a[ ] = {1, 2, 3, 4, 5 ; : int a[ 5] = {1, 2, 3, 4, 5, 6 ; 5, , 5, 1 5,, 1 ( 1) : int vote[ 6] ; ; ( ) ( 2) : { int vote[ 6] = {0, 0, 0, 0, 0, 0, x, max, k, k1; printf( " \nplease voting paper No. ( - 1 quit) " ) ; scanf( " % d", &x) ; while( x > 0&&x < 6) { vote[ x] = vote[ x] + 1; scanf( " % d", &x) ; max = vote[ 1] ; k1 = 1 ; for( k = 2; k < 6 ; k + + ) if( voet[ k] > max) max = vote[ k], k1 = k; for( k = 1; k < 6 ; k + + ) printf( " % 5d", vote[ k] ) ; printf( " \n The first voter is % d", k1) ;,, 6 a [ 6],, 193
207 194, x = 33, x[ 33 ] = x[ 33 ] + 1;, x x ( 0 < x < 6 ),, 6. 5, * : Element Value Striation 1 11 * * * * * * * * * * * 2 3 * * * 3 7 * * * * * * * 4 10 * * * * * * * * * * 5 20 * * * * * * * * * * * * * * * * * * * * ( 1), n *, n,,, ( 2) :, ; k < - 0; while( k < ArrSize) k + 1, arr[ k] m < - 0 while( m < arr[ k] ) * m < - m + 1 k < - k + 1 ( 3) : #define ArrSize 5 { int k, m, arr[ ArrSize] = { 11, 3, 7, 10, 20 ; printf( " \nelement \ tvalue \ t Striation \ n" ) ; for ( k = 0; k < ArrSize; k + + ) { printf( " % d \ t% d \ t ", k + 1, arr[ k] ) ;
208 for( m = 0; m < arr[ k] ; m + + ) printf( " * " ) ; printf( " \n" ) ; C,,,,,, 6. 6 ( 1), 5 ( ), 5,,, i, i, i ( 2) : : arr_insert( int a[ ], int m, int len) n < - 0 while( n < len) if( m < a[ n] ) s < - len - 1 while( s > = n) a[ s + 1] < - a[ s] a[ n] < - m ; s < - s - 1 n < - n + 1 if ( m > a[ len - 1] ) a[ len] < - m len < - len
209 196 len ( 3) : #define ARRLEN 20 { int arr_insert( int a[ ], int m, int len) ; int n, m, len, arr[ ARRLEN] ; len = 8; for( n = 0; n < len; n + + ) scanf( " % d", &arr[ n] ) ; printf( " input inserted a number: " ) ; scanf( " % d", &m) ; len = arr_insert( arr, m, len) ; / * len * / for( n = 0; n < len; n + + ) printf( " % d \ t", arr[ n] ) ; int arr_insert( int a[ ], int m, int len) { int n, s; for( n = 0; n < len; n + + ) if( m < a[ n] ) { for( s = len - 1; s > = n; s - - ) a[ s + 1] = a[ s] ; a[ n] = m; break; if ( m > a[ len - 1] ) a[ len] = m; len + + ; return len;, 8, 8, m : len = arr_insert( arr, m, len) ; arr, a[ ] main( ) arr[ ] a[ ] arr[ ], m, len + +,
210 C,,, : int arr[ 10], * ptr;, ptr arr ptr = &arr[ i] ptr i ( i), ptr = &arr[ 0] ptr = arr, ptr, ( * ) ptr = &arr [ i], * ptr arr[ i], : * ptr = < > scanf( % d, ptr) ; :,, arr = ptr arr + + ;, : ptr = arr ptr + +,, 3 :, : arr[ i], : * ( arr + i), : * ( ptr + i) 6. 7 { int arr[ 5], i, * ptr; 6. 8 ptr = arr; printf( " \ninput value of array: " ) ; for( i = 0 ; i < 5; i + + ) scanf( " % d", arr + i) ; printf( " \n" ) ; for( i = 0 ; i < 5; i + + ) printf( " \n" ) ; printf( " * ( arr + % d) = % d ", i, * ( arr + i) ) ; for( i = 0 ; i < 5; i + + ) printf( " * ( ptr + % d) = % d ", i, * ( ptr + + ) ) ; 197
211 198 ( 1) :,, 5 i, averandmax, ( 2) : #define ARRLEN 30 float averandmax( float * pa, float * pmax) ; { float sco[ ARRLEN], av, max = ; int i; printf( " \ninput 5 scores: \ n" ) ; for( i = 0 ; i < 5; i + + ) scanf( " % f", &sco[ i] ) ; av = averandmax( sco, &max) ; printf( " \naverage score and max is % 5. 2 f, % 5. 2f", av, max) ; float averandmax( float * pa, float * pmax) { int i; float s = 0; for( i = 0 ; i < 5; i + + ) { s = s + * pa; if ( * pa > * pmax) * pmax = * pa; pa + + ; return s/5; 6. 9 #define ARRLEN 20 { int arr_insert( int * pa, int m, int len) ; int * pn, m, len, arr[ ARRLEN] ; len = 5; pn = arr; for( ; pn < arr + len; ) scanf( " % d", pn + + ) ; printf( " input inserted a number: " ) ;
212 scanf( " % d", &m) ; len = arr_insert( arr, m, len) ; pn = arr; for( ; pn < arr + len; pn + + ) printf( " % d \ t", * pn) ; int arr_insert( int * pa, int m, int len) { int * pn, * ps; pn = pa; for( ; pn < pa + len; pn + + ) if( m < * pn) { for( ps = pa + len - 1; ps > = pn; ps - - ) * ( ps + 1) = * ps; * pn = m; break; if ( m > * ( pa + len - 1) ) * ( pa + len) = m; len + + ; return len;,, m arr_insert( ), 3 : ( 1) ,,,, 1 ) ( Bubble sorting),,,, ( ), n, n - 1, ( ) : : bubble_sort( int arr[ ], int size) i, j temp, flag;
213 200 i < - 0 while( i < size) flag < - 0 j < - size - 1 while( j > i) if( arr[ j] < arr[ j - 1] ) arr[ j] arr[ j - 1 ] flag < - 1 j < - j - 1 if( flag = 0) void outarray( int arr[ ], int size) ; void bubble_sort( int arr[ ], int size) ; { int a[ ] = {5, 6, 2, 9, 10, 3, 4, 7, 8, 1 ; int n; n = sizeof( a) / sizeof( int) ; printf( " Before sorting... \n" ) ; outarray( a, n) ; bubble_sort( a, n) ; printf( " After sorting... \ n" ) ; outarray( a, n) ; void bubble_sort( int arr[ ], int size) { int temp, flag; int i, j; for ( i = 0 ; i < size; i + + ) { flag = 0; for ( j = size - 1 ; j > i; j - - ) { if ( arr[ j] < arr[ j - 1 ] ) { temp = arr[ j] ; arr[ j] = arr[ j - 1] ; arr[ j - 1] = temp; flag = 1 ;
214 if ( flag = = 0) break; void outarray( int arr[ ], int size) { int i; for ( i = 0 ; i < size; i + + ) printf( " % d \ t", arr[ i] ) ; printf( " \n" ) ;, outarray( ) bubble_ sort( ),,, n,,, 2 ) ( Swap sorting),,,, n - 1 : swap_sort( int arr[ ], int size) i, j temp; i < - 0 while( i < size) j < - i + 1 while( j < size) if( arr[ j] < arr[ i] ) arr[ i] arr[ j] j < - j + 1 i < - i void outarray( int arr[ ], int size) ; void swap_sort( int arr[ ], int size) ; { int a[ ] = {5, 6, 2, 9, 10, 3, 4, 7, 8, 1 ; int n; n = sizeof( a) / sizeof( int) ; printf( " Before sorting... \n" ) ; 201
215 202 outarray( a, n) ; swap_sort( a, n) ; printf( " After sorting... \ n" ) ; outarray( a, n) ; void swap_sort( int arr[ ], int size) { int temp; int i, j; for ( i = 0 ; i < size; i + + ) for ( j = i + 1; j < size; j + + ) if ( arr[ j] < arr[ i] ) { temp = arr[ i] ; arr[ i] = arr[ j] ; arr[ j] = temp; void outarray( int arr[ ], int size) { int i; for ( i = 0 ; i < size; i + + ) printf( " % d \ t", arr[ i] ) ; printf( " \n" ) ; 3 ) ( Select sorting),,, : , 9, 1, n - 1 n - 1 : ( k = 5) ; : n,, k, arr [ 0] arr[ k], :
216 : select_sort( int arr[ ], int size) i, j temp k i < - 0 while( i < size) k < - i; j < - i + 1 while( j < size) if( arr[ j] < arr[ k] ) k < - j; j < - j + 1 if( k i) arr[ i] arr[ k] i < - i void outarray( int arr[ ], int size) ; void select_sort( int arr[ ], int size) ; { int a[ ] = {5, 6, 2, 9, 10, 3, 4, 7, 8, 1 ; int n; n = sizeof( a) / sizeof( int) ; printf( " Before sorting... \n" ) ; outarray( a, n) ; select_sort( a, n) ; printf( " After sorting... \ n" ) ; outarray( a, n) ; void select_sort( int arr[ ], int size) { int i, j, k; int temp; for ( i = 0 ; i < size; i + + ) { k = i; for ( j = i + 1; j < size; j + + ) if ( arr[ j] < arr[ k] ) k = j; if ( k! = i) temp = arr[ i], arr[ i] = arr[ k], arr[ k] = temp; 203
217 204 void outarray( int arr[ ], int size) { int i; for ( i = 0 ; i < size; i + + ) printf( " % d \ t", arr[ i] ) ; printf( " \n" ) ; 4 ) ( Insert sorting),,, : : 1, : : insert_sort( int arr[ ], int size) i, j temp i < - 1 While( i < size) temp < - arr[ i] j < - i - 1 while( j > = 0) if( temp < arr[ j] ) arr[ j + 1 ] < - arr[ j] else j < - j - 1 arr[ j + 1 ] < - temp i < - i void outarray( int arr[ ], int size) ;
218 void insert_sort( int arr[ ], int size) ; { int a[ ] = {5, 6, 2, 9, 10, 3, 4, 7, 8, 1 ; int n; n = sizeof( a) / sizeof( int) ; printf( " Before sorting... \n" ) ; outarray( a, n) ; insert_sort( a, n) ; printf( " After sorting... \ n" ) ; outarray( a, n) ; void insert_sort( int arr[ ], int size) { int i, j; int temp; for ( i = 1 ; i < size; i + + ) { temp = arr[ i] ; for ( j = i - 1; j > = 0; j - - ) if ( temp < arr[ j] ) arr[ j + 1 ] = arr[ j] ; else break; arr[ j + 1] = temp; void outarray( int arr[ ], int size) { int i; for ( i = 0 ; i < size; i + + ) printf( " % d \ t", arr[ i] ) ; printf( " \n" ) ; ,,,,, : 1 ),
219 206,,,,, 50%,, 50%, - 1 : SequenceSearch( int arr[ ], int key, int size) n n < - 0 While( n < size) if ( arr[ n] = key) n #include < stdlib. h > #include < time. h > #define ARRSIZE 300 int SequenceSearch( int arr[ ], int key, int size) ; { int x, a[ ARRSIZE], key, size; randomize( ) ; printf( " \ninput list size( < 300 ) : " ) ; scanf( " % d", &size) ; printf( " Auto make a list: \n" ) ; for( x = 0; x < size; x + + ) { a[ x] = rand( ) % 1000; printf( " % d \ t", a[ x] ) ; printf( " \ninput Search key: " ) ; scanf( " % d", &key) ; x = SequenceSearch( a, key, size) ; if ( x! = - 1) printf( " found value in element % d \n", x) ; else printf( " Value not found \n" ) ;
220 int SequenceSearch( int arr[ ], int key, int size) { int n; for ( n = 0; n < size; n + + ) if ( arr[ n] = = key) return n; return - 1;, 300 a[ ], x, key, size, 100, a[ ] rand( ), randomize( ) ; 100 3, key,,, ,, 2 ), ( ),,,,,,,, 1 024,, , 2, , 10 1, ( ) ;,,,, key = 21 : < key < key = key,,,,, 100, 50, 20 ( 2 20 = ) : : BinarySearch( int arr[ ], int key, int size) low, high, middle; ; low < - 0, high < - size
221 208 while( low < = high) middle < - ( low + high) /2 if( key = arr[ middle] ) middle else if( key > arr[ middle] ) low < - middle + 1 else high < - middle #include < stdlib. h > #include < time. h > #define ARRSIZE 300 int BinarySearch( int arr[ ], int key, int size) ; void insert_sort( int arr[ ], int size) ; { int x, a[ ARRSIZE], key, size; randomize( ) ; printf( " \ninput list size( < 300 ) : " ) ; scanf( " % d", &size) ; printf( " Auto make a list: \n" ) ; for( x = 0; x < size; x + + ) { a[ x] = rand( ) % 1000; printf( " % d \ t", a[ x] ) ; printf( " \n sorting a list: \ n" ) ; insert_sort( a, size) ; for( x = 0; x < size; x + + ) printf( " % d \ t", a[ x] ) ; printf( " \n input Search key: " ) ; scanf( " % d", &key) ; x = BinarySearch( a, key, size) ; if ( x! = - 1) printf( " found value in element % d \n", x) ; else printf( " Value not found \n" ) ; int BinarySearch( int arr[ ], int key, int size)
222 { int low = 0, high = size - 1, middle; int count = 0 ; while( low < = high) { middle = ( low + high) /2 ; count + + ; if ( key = = arr[ middle] ) { printf( " compare count = % d \ n", count) ; return middle; else if( key > arr[ middle] ) low = middle + 1 ; else high = middle - 1; printf( " compare count = % d \ n", count) ; return - 1; void insert_sort( int arr[ ], int size) { int i, j; int temp; for ( i = 1 ; i < size; i + + ) { temp = arr[ i] ; for ( j = i - 1; j > = 0; j - - ) if ( temp < arr[ j] ) arr[ j + 1 ] = arr[ j] ; else break; arr[ j + 1] = temp; BinarySearch( ) insert_sort ( ) , ( size = 100 ), 100, key,,, count, 209
223 ,, C 2, N N,,,,,,, N ( N - 1 ) : [ ] [ ] ; : int a2[ 3 ] [ 4], matrix[ 10] [ 10] ; float class_grade[ 35] [ 19] ; 2 1, a2, matrix 10* 10, class_grade 19, n m,,,, N, :,,, C, a2 [ 3 ] [ 4] : a2 [ 0] [ 0] a2[ 0] [ 1 ] a2[ 0] [ 2] a2[ 0 ] [ 3 ] a2[ 1] [ 0] a2[ 1] [ 1] a2 [ 1] [ 2] a2[ 1] [ 3 ] a2[ 2] [ 0] a2[ 2 ] [ 1 ] a2[ 2] [ 2] a2[ 2] [ 3] 3 * 4 = 12 0,, 0 4, 1 2 4,, C a2[ 3] [ 4], 3, a[ 0], a[ 1], a[ 2] 3 3 4,, a [ 0 ] a [ 0] [ 0], a [ 0] [ 1 ], a [ 0] [ 2], a[ 0] [ 3] a [ 0 ], a[ 1 ], a[ 2], 3, : int a[ 5] [ 3] = { {80, 75, 92, {61, 65, 71, {59, 63, 70,
224 {85, 87, 90, {76, 77, 85 ; : int a[ 5] [ 3] = { 80, 75, 92, 61, 65, 71, 59, 63, 70, 85, 87, 90, 76, 77, 85 ;, 0 : int a[ 3] [ 3] = { {1, {0, 2, {1, 0, 3 ; : , : int a[ 3] [ 3] = {1, 2, 3, 4, 5, 6, 7, 8, 9 ; : int a[ ] [ 3 ] = {1, 2, 3, 4, 5, 6, 7, 8, 9 ; a[ 3] [ 4] b[ 3] : a, b, a, b C : { int a[ ] [ 4] = {3, 16, 87, 65, 4, 32, 11, 108, 10, 25, 12, 27 ; int b[ 3], i, j, l; for( i = 0 ; i < = 2; i + + ) { l = a[ i] [ 0] ; for ( j = 1 ; j < = 3; j + + ) if ( a[ i] [ j] > l) l = a[ i] [ j] ; b[ i] = l; printf( " \narray a: \ n" ) ; for( i = 0 ; i < = 2; i + + ) { for ( j = 0 ; j < = 3; j + + ) printf( " % 5d", a[ i] [ j] ) ; printf( " \n" ) ; printf( " \narray b: \n" ) ; for( i = 0 ; i < = 2; i + + ) printf( " % 5d", b[ i] ) ; 211
225 for for, 0 l, l, l l l, l b [ i], b a for a b :, ; ( 1) : score [ 300] [ 9 ] / * 0, 1 8 * / n score m /* m * / row < - 0 while ( row < n) if ( score[ row] [ 0] = = m) break; if ( row > = n) return; s < - 0 col < - 1 while ( col < ) s < - s + score[ row] [ col] col < - col + 1 ( m) col < - 1 while ( col < ) s < - 0 row < - 0
226 while( row < ) s < - s + score[ row] [ col] row < - row + 1 s / n col < - col + 1 ( 2) C : #include < stdlib. h > #include < time. h > #define ARRrow 300 #define ARRcol 9 { int row, col, n, s ; long score[ ARRrow] [ ARRcol], m; randomize( ) ; printf( " \ninput score list size( < 300) : " ) ; scanf( " % d", &n) ; printf( " Auto make a score list: \ n" ) ; for ( row = 0; row < n; row + + ) { score[ row] [ 0] = L + rand( ) % ; printf( " % ld \ t", score[ row] [ 0] ) ; for ( col = 1 ; col < ARRcol; col + + ) { score[ row] [ col] = rand( ) % 101 ; printf( " % d \ t", score[ row] [ col] ) ; printf( " \n" ) ; printf( " \n input student no: " ) ; scanf ( " % ld", &m ) ; for ( row = 0; row < n; row + + ) if ( score[ row] [ 0] = = m) break; if ( row > = n) return; s = 0; for ( col = 1; col < ARRcol; col + + ) s + = score[ row] [ col] ; printf( " \n student no: % ld score list: \ n", m) ; 213
227 214 printf( " courses no: \ t" ) ; for ( col = 1; col < ARRcol; col + + ) printf( " % d \ t", col) ; printf( " * AVG* \ n \t \t" ) ; for ( col = 1; col < ARRcol; col + + ) printf( " % d \ t", score[ row] [ col] ) ; printf ( " % d", s / ( ARRcol - 1 ) ) ; printf( " \n all student average score list: \ n \ t \ t" ) ; for( col = 1; col < ARRcol; col + + ) { s = 0; for ( row = 0; row < n; row + + ) s + = score[ row] [ col] ; printf( " % d \ t", s /n) ;,, for, 1,, 8,,, 8, s s 0 s ( ARRcol - 1), 2, ( ),,,,, ( 3 4 ) { int max_value( int arr1 [ ] [ 4 ] ) ; int arr[ 3] [ 4] = {1, 3, 5, 7, 2, 4, 6, 8, 15, 17, 34, 12 ; printf( " Max value is: % d \ n", max_value( arr) ) ; int max_value( int arr1[ ] [ 4] ) { int i, j, max; max = arr1[ 0] [ 0 ] ; for ( i = 0 ; i < 3; i + + ) for ( j = 0; j < 4 ; j + + ) if ( arr1[ i] [ j] > max)
228 max = arr1[ i] [ j] ; return max;,, :, max,, max,, max, : #include < stdlib. h > #include < time. h > #define ROW 8 #define COL 9 { int max_value( int arr1 [ ] [ COL] ) ; int arr[ ROW] [ COL], row, col; randomize( ) ; for ( row = 0; row < ROW; row + + ) { for( col = 0 ; col < COL; col + + ) { arr[ row] [ col] = rand( ) % ; printf( " % d \ t", arr[ row] [ col] ) ; printf( " \n" ) ; printf( " \nmax value is: % d \ n", max_value( arr) ) ; int max_value( int arr1[ ] [ COL] ) { int max, row, col; max = arr1[ 0] [ 0 ] ; for ( row = 0; row < ROW; row + + ) for ( col = 0; col < COL; col + + ) if ( arr1[ row] [ col] > max) max = arr1[ row] [ col] ; return max;,,,, ( 215
229 216 ), C N* M M* N #define M 2 #define N 3 void transpose( int a1[ ] [ N], int a2[ ] [ M] ) ; { int arr1[ M] [ N] = { {2, 4, 6, {1, 3, 5, arr2[ N] [ M], i, j; printf( " Array arr1: \ n" ) ; for ( i = 0 ; i < M; i + + ) { for ( j = 0 ; j < N; j + + ) printf( " % 5d", arr1[ i] [ j] ) ; printf( " \n" ) ; transpose( arr1, arr2) ; printf( " Array arr2: \ n" ) ; for ( i = 0 ; i < N; i + + ) { for ( j = 0 ; j < M; j + + ) printf( " % 5d", arr2[ i] [ j] ) ; printf( " \n" ) ; void transpose( int a1[ ] [ N], int a2[ ] [ M] ) { int i, j; for ( i = 0 ; i < M; i + + ) for ( j = 0; j < N; j + + ) a2 [ j] [ i] = a1 [ i] [ j] ; : n ( 1) : : 1 1 ; 2 n* n : 1 1;
230 1, n; n, 1; ( ), 1 n, #define N 16 { int plot[ N] [ N] ; int i, j, k, p, n; p = 1; while( p = = 1 ) { printf( " \ninput a odd rank of magic matrix < 16 : " ) ; scanf( " % d", &n) ; if ( ( n > 1&&n < = 15) &&( n% 2! = 0) ) { printf( " The rank of magic matrix is % d \n", n) ; p = 0; for ( i = 1 ; i < = n; i + + ) for ( j = 1; j < = n; j + + ) plot[ i] [ j] = 0; i = 1; j = n /2 + 1 ; plot[ i] [ j] = 1; for ( k = 2; k < = n* n; k + + ) { i = i - 1; j = j + 1; if ( i < 1&&j > n) { i + = 2; j = j - 1; plot[ i] [ j] = k; continue; if ( i < 1) i = n; if ( j > n) j = 1; while( plot[ i] [ j]! = 0) { i = i + 2; 217
231 218 j = j - 1; if ( j < 1) j = n; if ( i > n) i = 1; plot[ i] [ j] = k; for ( i = 1 ; i < = n; i + + ) { for ( j = 1 ; j < = n; j + + ) printf( " % d \ t", plot[ i] [ j] ) ; printf( " \n" ) ;,, 16, 1, plot ( 1), 1 1 k ( 2) ( 4) 2, 1 n,,, continue k 3 4, ), (, ), : int arr[ 3] [ 4] ; : arr[ 0 ] [ 4] arr[ 1 ] [ 4] arr[ 2] [ 4 ] 3, 4 : arr[ 0], arr[ 1], arr[ 2] arr arr[ 0 ] arr[ 0] [ 0] arr[ 0] [ 1] arr[ 0] [ 2] arr[ 0] [ 3] arr[ 1 ] arr[ 1] [ 0] arr[ 1] [ 1] arr[ 1] [ 2] arr[ 1] [ 3] arr[ 2 ] arr[ 2] [ 0] arr[ 2] [ 1] arr[ 2] [ 3] arr[ 2] [ 3]
232 , arr, 0, arr[ 0] : arr = arr[ 0] = &arr[ 0] [ 0] + i i arr + i arr i, n, n, arr[ i] + j i j, &arr[ i] [ j] arr[ i] * ( arr + i),, * ( arr + i) + j &a[ i] [ j] : arr[ i] + j = * ( arr + i) + j = &arr[ i] [ j], * ( * ( arr + i) + j) * ( arr[ i] + j) arr [ i] [ j] : arr + i *,, * ( arr + i) + j arr + i j arr[ 0 ] &,, &arr[ 0 ], arr &arr[ i] arr[ i], &arr[ i] + 1 arr[ i] + 1,,,,, 2 ),,, ( ) { int add( int * arr, int n) ; int i, j, arr[ 4] [ 3] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, * ptr; ptr = arr[ 0] ; for ( i = 0 ; i < 4 ; i + + ) { for ( j = 0 ; j < 3; j + + ) printf( " % 4d", * ptr + + ) ; printf( " \n " ) ; ptr = arr[ 0] ; printf( " The array all elements sum = % d \ n", add( ptr, 12) ) ; int add( int * arr, int n) { int i, sum = 0; for ( i = 0 ; i < n; i + +, arr + + ) sum + = * arr; return sum; 219
233 220 3 ) m, C, m : ( * ) [ ] ; : int ( * ptr) [ 10 ] ; 10 ptr n n ptr , 11,, m : m,, : int ( * ptr) [ 10], * p; ptr, ptr = ptr + 2; ptr 21,, : printf( % d, * ptr) ; ptr p, printf ( % d, * p) ; m { int a[ 3] [ 4] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 ; int ( * p) [ 4] ; int i, j; p = a; for ( i = 0 ; i < 3; i + + ) { for ( j = 0 ; j < 4; j + + ) printf( " % 5d ", * ( * ( p + i) + j) ) ; printf( " \n" ) ;, p 4 3 4, p 0, j 4, * ( * ( p + i) + j) 0 i, * ( p + i) i ,, 2, : Auto make a 6* 6 matrix:
234 output 6 6 matrix in 3 col swap result: , 3 79, 3 55, , 3 ( 1) 6 6, x, y, 2 p0, p3, 1 3 p; 6 6 ; p 2 * ARRSIZE - 1; p = ( int ( * ) [ 3 ] a;, p0, p3 p3 p + + ; x p, y ;, x, y #include < stdlib. h > #include < time. h > #define ARRSIZE 6 { int x, y, a[ ARRSIZE] [ ARRSIZE], * p0, * p3, ( * p) [ 3] ; randomize( ) ; printf( " Auto make a 6* 6 matrix: \ n" ) ; for( x = 0; x < ARRSIZE; x + + ) { for ( y = 0; y < ARRSIZE; y + + ) { a[ x] [ y] = rand( ) % 100 ; printf( " % d \ t", a[ x] [ y] ) ; printf( " \n" ) ; printf( " \noutput 6* 6 matrix in 3 col swap result: \ n" ) ; 221
235 222 p = ( int ( * ) [ 3 ] a; for ( x = 1; x < ARRSIZE* 2; x + + ) { p0 = ( int * ) p; p + + ; p3 = ( int * ) p; y = * p0; * p0 = * p3; * p3 = y; p0 = p3; for ( x = 0; x < ARRSIZE; x + + ) { for ( y = 0; y < ARRSIZE; y + + ) printf ( " % d \ t", a[ x] [ y] ) ; printf( " \ n" ) ; , C NULL( \ 0 ), ASCII C : The C program :, \ n, C, : T h e C p r o g r a m \ \0
236 \ n \0 \0 : \0, \0 C,, : char s1[ 100] ; s1,,, : char s1[ 100] = { The C Programm ; cahr s2[ 100] = The C Programm ; char s3[ ] = The C Programm ;,,, : char * ps = s1; s1 ps s1, * ps s1 223 T h e C p r o g r a m \0 ps,,, C : ( ) ; scanf( % s, ) ; gets( ),, & scanf( ), gets( ), : char string[ 100 ] ;
237 224 scanf( % s, string) ; gets( string) ; : printf( % s, ) ; puts( ) ; : printf( % s, string) ; puts( string) ; string 99 ( \0 ) 2 : char * ps; for( ps = string; * ps ; ps + = 2) putchar( * ps) ;, printf( ) puts( ) : char * ps, n = 10; ps = " this is a book" ; printf( " % s \ n", ps + n) ; puts( ps + 8 ) ; : book a book ps, ps, ps = ps + 10, ps b, NULL : " book" ( ) ( 1) :, \0, 1 ( 2) : { char str[ 100 ], * p, sum = 0 ; p = str ; gets( p) ; while( * p! { sum + + ; p + + ; putchar( \ n ) ; = \0 ) printf( " \n The string length = % d", sum) ; : int locateofchar( char * ps, char ch) ( 1) : 1 count,,, 0 ps \0,
238 ( 2) : int locateofchar( char * ps, char ch) ; { char str[ 100 ], ch; printf( " \ninput a string: " ) ; gets( str) ; printf( " \n input a character: " ) ; ch = getchar( ) ; printf( " \nthe locate of \ % c \ in \" % s\" is % d", ch, str, locateofchar( str, ch) ) ; int locateofchar( char * ps, char ch) { int count = 1 ; while( * ps) { if ( * ps = = ch) return count; ps + + ; count + + ; return 0; gets( ), getchar( ),, \ \ ( ) ( 1) : str1, str2 str1, str1, ( \ 0 ), str2 str1, str2 ( \0 ) ( 2) : { char str1[ 80 ], str2[ 40], * p1 = str1, * p2 = str2; printf( " \ninput first string: " ) ; gets( p1) ; printf( " \ninput second string: " ) ; gets( p2) ; while( * p1 + + ) ; 225
239 p1 - - ; while( ( * p1 + + = * p2 + + )! ; printf( " \nthe string connect: " ) ; puts( str1) ; = \0 ),, p1 str1, * p1 NULL,,, p1 1, NULL, 1, p1 str1 ( NULL), * p1 = * p2; str2 str1, p1 + +, p2 + + ; p2 str2, NULL( ) 2, puts( p1) ; str1? C,, 9, string. h, #include < string. h > ( 1) (, NULL) unsigned strlen( char * s) ( 2) char * strcat( char * s1, char * s2) s2 s1, s1 ( 3) char * strcpy( char * s1, char * s2) s2 s1, s1, \0, \0 C, str1 = str2; ( 4) int strcmp( char * str1, char * str2 ), : R < 0 R = 0 R > 0 str1 str2 str1 str2 str1 str2 2, \0
240 \ 0, C 2 : str1 = = str2 ( 5) str1 > str2 char * strchr( char * s, int ch) ch ( ) ( 6) char * strncat( char * s1, char * s2, int n ) s2 n s1 ( 7) int strncmp( char * s1, char * s2, int n) s1 s2 n 0 ( 8) char * strncpy( char * s1, char * s2, int n) s2 n s1, s1 ( 9) char * strstr( char * s1, char * s2) s2 s1, NULL , #include < string. h > { char str1[ 40], str2[ 40] ; int n; printf( " \ ninput str1 : " ) ; gets( str1) ; printf( " Input str2: " ) ; gets( str2) ; n = strcmp( str1, str2) ; if ( n > 0) printf( " str1 > str2" ) ; else if ( n < 0) else printf ( " str1 < str2" ) ; printf( " str1 = str2" ) ;, strcat 227
241 228 ( 1) : 1 \0, 2 1 ( 2) : #include < string. h > { void mystrcat( char str1[ ], char str2[ ] ) ; char s1[ 80], s2 [ 40] ; printf( " Input strint s1: " ) ; gets( s1 ) ; printf( " Input strint s2: " ) ; gets( s2 ) ; mystrcat( s1, s2) ; puts( s1) ; void mystrcat( char str1[ ], char str2[ ] ) { int i; i = strlen( str1) ; strcpy( str1 + i, str2 ) ; 1, 2 ( 2 1 ), 1 abcdef, 2 d12345, abcd12345def ( 1) : 1 2 ; 1 ; ; \0 ( 2) : #include < string. h > { void insert_string( char s1[ ], char s2[ ] ) ; char str1[ 80 ], str2[ 40] ; printf( " Input strint str1: " ) ; gets( str1) ; printf( " Input strint str2: " ) ; gets( str2) ;
242 insert_string( str1, str2) ; puts( str1) ; void insert_string( char s1[ ], char s2[ ] ) { char temp[ 80] ; int i; for ( i = 0 ; s1[ i]! = s2[ 0] ; i + + ) ; strcpy( temp, &s1 [ i] ) ; strcpy( &s1[ i], s2) ; strcpy( &s1[ i] + strlen( s2), temp) ; s1 s2 ( 1) :,,, ; s2 ; s1 s2 ; s2 s1 s2 ( 2) : delete_string( char * s1, char * s2 ) len < - s2 k < - 0 while( s1 ) if ( s1 k s2 ) s1 k s2 k < - k - 1 k < - k + 1 s1 ( 3) : #include < string. h > char * delete_string( char * s1, char * s2 ) { int k, len = strlen( s2 ) ; for ( k = 0 ; * ( s1 + k) ; k + + ) if ( strncmp( s1 + k, s2, len) = = 0) { strcpy( s1 + k, s1 + k + len) ; k - - ; return s1 ; 229
243 230 { char s1[ 80], s2[ 10] ; : gets( s1) ; gets( s2) ; puts( delete_string( s1, s2) ) ; 11 the People s Republic of China Japan the Republic of India the Republic of Korea Malaysia the Islamic Republic of Pakistan the Kingdom of Thailand the Republic of Singapore the Republic of the Philippines the Socialist Republic of Vietnam the Union of Myanmar ( 1) :,,, ( 2) : #include < string. h > { char temp[ 80], cs[ 20] [ 80] ; int i, j, p; printf( " input country s name: \ n" ) ; for( i = 0 ; i < 8; i + + ) gets( cs[ i] ) ; printf( " \n" ) ; for( i = 0 ; i < 8; i + + ) { p = i; strcpy( temp, cs[ i] ) ; for ( j = i + 1; j < 8; j + + ) if ( strcmp( cs[ j], temp) < 0 ) { p = j; strcpy( temp, cs[ j] ) ;
244 if ( p! = i) { strcpy( temp, cs[ i] ) ; strcpy( cs[ i], cs[ p] ) ; strcpy( cs[ p], temp) ; puts( cs[ i] ) ; printf( " \n" ) ; 1 for, gets 8, ( 20 ) gets cs[ i] cs [ i] temp, i p, temp cs[ i], temp temp, p p i cs[ i], cs[ i] temp cs i, ASCII, : ABCDeFGH, : eabcdfgh ( 1) p; max, q, i; * ( p + i) NULL,, ; i + +, * ( p + i) > max, max, max, q; ; q > p,, ; * q = * ( q - 1) ; q q, q - - ; ;, 231 ( 2) : void fun ( char * p) { char max, * q; int i = 0; max = * p; while ( * ( p + i) )
245 232 { i + + ; if ( max < * ( p + i) ) { max = * ( p + i) ; q = p + i; while ( p < q) { * q = * ( q - 1) ; q - - ; * p = max; { char str[ 80] ; printf ( " Enter a string: " ) ; gets( str) ; fun( str) ; printf( " \n The last string of changed \ n" ) ; puts( str) ;, printf, printf PF, { int a[ 3] [ 4] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, k; char * PF, * PF2; PF = " % d, % d, % d, % d \ n" ; PF2 = % d - % d - % d \ n ; for ( k = 0; k < 3 ; k + + ) printf( PF, a[ k] [ 0 ], a[ k] [ 1], a[ k] [ 2], a[ k] [ 3] ) ; for ( k = 0; k < 4 ; k + + ) printf( PF2, a[ 0] [ k], a[ 1 ] [ k], a[ 2 ] [ k] ) ; ,
246 : * [ ] ; : int * pa[ 3 ] pa 3,, : int a[ 3] [ 3] = {1, 2, 3, 4, 5, 6, 7, 8, 9 ; int * pa[ 3 ] = {a[ 0 ], a[ 1], a[ 2] ; pa a a[ 0] a[ 0] [ 0] a[ 0] [ 1] a[ 0] [ 2] a[ 1] a[ 1] [ 0] a[ 1] [ 1] a[ 1] [ 2] a[ 2] a[ 2] [ 0] a[ 2] [ 1] a[ 2] [ 2] int * p[ 4] ; m int ( * p) [ 4 ],, ( ),, 3,, C month[ ], 12 : char * month[ ] = { January, February, March, April, May, June, July, August, September, October, November, December ;, 1 7, { int i; char * day_name( int n) ; printf( " input Day No: \n" ) ; scanf( " % d", &i) ; printf( " Day No: % 2d - - > % s \ n", i, day_name( i) ) ; char * day_name( int n) { char * name[ ] = { " Illegal day", " Monday", " Tuesday", " Wednesday", 233
247 234 " Thursday", " Friday", " Saturday", " Sunday" ; return ( ( n < 1 n > 7 ) name[ 0] : name[ n] ) ;, name [ ], 8, name[ 0] " Illegal day", Day_name, n 1 7 " Illegal day", % s #include < string. h > #define N 5 { void sort( char * arr1[ ], int n) ; char * string[ N] = {" korea", " japan", " malaysia", " india", " pakistan" ; int i; sort ( string, N) ; for ( i = 0 ; i < N; i + + ) puts( string[ i] ) ; void sort( char * arr1[ ], int n) { int i, j, k; char * temp; for ( i = 0 ; i < n - 1; i + + ) { k = i; for ( j = i + 1; j < n; j + + ) if ( strcmp( arr1[ j], arr1[ k] ) > 0) k = j; if ( k! = i) temp = arr1[ i], arr1[ i] = arr1[ k], arr1[ k] = temp;,,, : * * ;, : * * * ;,,
248 C,,,,, : int * * pp; pp,, { int x, * p, * * pp; x = 10; p = &x; pp = &p; printf( " \nx = % d * * pp = % d \ n", x, * * pp) ;, p, x; pp, p pp x * * pp x 10 [ 6. 38] { char * string[ ] = { " basic", " fortran", " pascal", " lisp", * * ptr; int i; ptr = string; for ( i = 0 ; i < 4; i + + ) puts( * ( ptr + i) ) ; , (, - 1 ) { int stu1 [ ] = { 78, 98, 73, - 1, stu2[ ] = {100, 98, - 1, stu3[ ] = {88, - 1, stu4 [ ] = { 100, 78, 33, 65, - 1, stu5[ ] = {99, 88, - 1 ; int * grad[ 5], * * ptr, i; grad[ 0] = stu1 ; grad[ 1] = stu2 ; grad[ 2] = stu3 ; grad[ 3] = stu4 ; grad[ 4] = stu5 ; for( ptr = grad, i = 1 ; i < = 5; ptr + +, i + + ) { printf ( " scores of student % d: ", i) ; 235
249 while( * * ptr > = 0) { printf ( " % 5d", * * ptr) ; ( * ptr) + + ; printf( " \n" ) ; , C,, 2,, argc ; argv,, Windows, command, Regedit /1, " /1 " /1 C, TC , Arguments,,,, C mycopy. exe, : void main( int argc, char * argv[ ] ), : mycopy file1. txt file2. txt : argc = 3, argv[ 0 ] mycopy, argv[ 1]
250 file1. txt, argv[ 2 ] file2. txt void main( int argc, char * argv[ ] ) { while( - - argc > 0 ) : printf( " % s% c", * + + argv, ( argc > 1 : \ n ) ) ;, TC Run Arguments Windows : 237, s6-40. exe,, argc, argc 1 argv,, + + argv argv[ 1], 2,, : mychar. cpp mychar. exe TC , RUN Arguments, : Computer and C Language, : Computer and C Language Windows : mychar Computer and C Language n, n #include < stdlib. h > #include < math. h > void main( int argc, char * argv[ ] )
251 { int k = 0, n; n = atoi( * + + argv) ; printf( " \nk \ tk* k \tsqrt( k) \ n" ) ; while( k + + < n) printf( " % d \t% d \ t% f \n", k, k* k, sqrt( k) ) ; Run Arguments : 238, 1 ( 0 ) atoi( ), sqrt( ), k sqrt( ), % f , ( 1) : 1,, ;, NULL ( 2) : #include < string. h > void main( int argc, char * argv[ ] ) { char * search( char * str1, char * str2) ; char * ptr; if ( argc < 3) printf( " error!! Lose arguments \n" ) ; ptr = search( argv[ 1 ], argv[ 2] ) ; if ( ptr! = NULL) { strcpy( ptr, ptr + strlen( argv[ 2] ) ) ; else puts( argv[ 1] ) ; printf( " sub_string % s is not in main_string % s! \n", argv[ 2], argv[ 1] ) ;
252 char * search( char * str1, char * str2) { int len = strlen( str2) ; while ( ( str1 = strchr( str1, * str2) )! = NULL) if ( strncmp( str1, str2, len) = = 0) break; else str1 + + ; return str1; Run Arguments : 239, strncmp( str1, str2, n) 2 n, 0, 0 strchr( str, ch) str ch, ch, NULL 1, : 1,,,,, NULL search : char * search( char * str1, char * str2) { int len = strlen( str2) ; for ( ; strncmp( str1, str2, len)! = 0&&* ( str1 + len)! = \0 ; str1 + + ) ; return( * ( str1 + len)! = \0 str1: NULL) ;
253 ,,, ; ; ;, C,,, :,,,, : struct { ; ;,,, : struct student { char num[ 8] ; ; char name[ 20] ; char sex; int age; float score;, student, 5, 1, num, ; 2, name, ; 3, sex,, M F ; 4, age, ; 5, score,,,,
254 : struct student stu1, stu2 ; 2 : stu1, stu2, 2 student,, stu1 stu2 struct student num Name sex age score , 4 : 1 ) 3 ( 1) ( ) struct student { char num[ 8] ; char name[ 20] ; char sex; int age; float score; ; struct student stu1, stu2 ; ( 2) struct student { char num[ 8] ; char name[ 20] ; char sex; int age; float score; stu1, stu2; ( 3), struct { char num[ 8] ; 241
255 242 char name[ 20] ; char sex; int age; float score; stu1, stu2; 2 ), struct date { int month; int day; int year; struct student1 { char num[ 8] ; char name[ 20] ; char sex; int age; struct date birthday; float score; boy1, boy2; date, month( ) day( ) year( ) 3 boy1 boy2, birthday date, 3 ), ANSI C,, :.,. : boy1. num, boy2. sex 2 : boy1. birthday. month C scanf,, :
256 gets, ;, atoi atol atof : atoi( char * nptr), ; atol( char * nptr), ; atof( char * nptr), ( double) 3 stdlib. h, #include < stdlib. h > struct student { char num[ 8] ; ; char name[ 20] ; char sex; int age; float score; struct student stu1, stu2 ; { char temp[ 20] ; printf( " first one input: num, name, sex, age, score \ n" ) ; gets( stu1. num) ; gets( stu1. name) ; stu1. sex = getchar( ) ; getchar( ) ; gets( temp) ; stu1. age = atoi( temp) ; gets( temp) ; stu1. score = atof( temp) ; stu2 = stu1 ; printf( " Second input the num and name: \ n" ) ; gets( stu2. num) ; gets( stu2. name) ; printf( " first student information: \ n" ) ; printf( " % s % s % c % d % f\ n", stu1. num, stu1. name, stu1. sex, stu1. age, stu1. score) ; printf( " second student information: \ n" ) ; printf( " % s % s % c % d % f\ n", stu2. num, stu2. name, stu2. sex, stu2. age, stu2. score) ; 243
257 student, 2 stu1 stu2, age, score, gets( ), getchar( ), getchar( ), 2,, stu1 stu2, stu2 num, name 4 ),, : struct student s1 = { , LiBin, M, 19, ; : num name sex age score LiBin M : ; struct student { char num[ 8] ; char name[ 20] ; char sex; int age; float score; boy2, boy1 = { , " ZhangPing", M, 19, ; { boy2 = boy1 ; boy2. score = ; printf( " Number = % s \nname = % s \ n", boy2. num, boy2. name) ; printf( " Sex = % c \nage = % d \nscore = % f\n", boy2. sex, boy2. age, boy2. score) ;
258 typedef C typedef ( ),, : typedef ; : typedef int INTEGER; ( int) INTE- GER, int j, k; INTEGER j, k;, : typedef struct student { char num[ 8] ; char name[ 20] ; char sex; int age; float score; STU; struct student { char num[ 8] ; char name[ 20] ; char sex; int age; float score; ; typedef struct student STU; struct student STU, STU stu2, stu2, stu3 ; struct student stu1, stu2, stu3; typedef : typedef char STRING [ 80] ; STRING 80, STRING str; char str [ 80] ; :, : ( 1) Typedef char STRING[ 100] ; /* STRING 100 * / STRING c1, c2; char c1[ 100 ], c2[ 100] ; ( 2) typedef int * PNUM; /* PNUM * / 245
259 PNUM pn, pm; int * pn, * pm ; ( 3) typedef struct strname{ ST; / * ST * / ST a[ 10 ] ; struct strname { a[ 10] ; ,,,,, : typedef struct student { char num[ 8] ; STU; char name[ 20] ; char sex; int age; float score; STU mclass[ 35] ; mclass, 35, mclass[ 0] mclass[ 34 ] struct student mclass 35, : STU mclass[ 35 ] = { { , " Li ping", " M", 445, { , " Zhang ping", " M", , { , " He fang", " F", , { , " Cheng ling", " F", 587, { , " Wang ming", " M", 558 ;,,, : [ ]. : mclass[ 2]. name mclass[ 2]. count ( 1)
260 , ; count < - 0, s < - 0 i < - 0 while( i < 5) s < - s + mclass[ i]. score / * * / count < - count + 1 / * * / i < - i + 1 s /coung, count ( 2) : typedef struct student { char num[ 9] ; STU; char name[ 20] ; char sex; int age; float score; STU mclass[ 35 ] = { { " ", " Li ping", M, 19, 545, { " ", " Zhang ping", M, 16, , { " ", " He fang", F, 17, , { " ", " Cheng ling", F, 18, , { " ", " Wang ming", M, 17, ; { int i, count = 0; float s = 0; for( i = 0 ; i < 5; i + + ) { s + = mclass[ i]. score; count + + ; printf( " % 10 s% 20s \ t% c \ t% d \t% f\ n", mclass[ i]. num, mclass[ i]. name, mclass[ i]. sex, mclass[ i]. age, mclass[ i]. score) ; printf( " average = % f \ncount = % d \n", s / count, count) ; mclass, 35, 5 247
261 : 8, 9, NULL main for 5 score s, count 1,,, : ( 1), : struct ( ) { return ; ( 2) ( ),, ( 3),, : ( struct ) { : ( ) ; ( 4) ( ), ( ) ( ) 6. 46, #include < stdlib. h > #define N 6 typedef struct stud_type { char name[ 20] ; int age; float score;
262 STU; { STU input( int n) ; void print( STU x, int n) ; STU stu[ N] ; int i; for ( i = 0 ; i < N; i + + ) stu[ i] = input( i) ; for ( i = 0 ; i < N; i + + ) print( stu[ i], i) ; STU input( int n) { STU x; char in_buf[ 20] ; printf( " \ninput all data of stu[ % d] : \ n", n) ; gets( x. name) ; gets( in_buf) ; x. age = atoi( in_buf) ; gets( in_buf) ; x. score = atof( in_buf) ; return( x) ; void print( STU x, int n) { printf( " Student% d: % s, % d, % 6. 2 f\ n", n, x. name, x. age, x. score) ; ), : struct * ; : typedef struct stud_type { char name[ 20] ; int age; float score; STU; STU * pt, stu1;
263 pt, struct stud_type pt,, stu1 stu1 pt, : pt = &stu1; stu1. name stu1. age stu1. score 250 pt : ( * ). ; : ( * pt). name ( * pt). score : - > ; : pt - > name; pt - > score - > : pt #include < stdlib. h > struct date { int day; ; int month; int year; struct stutype { char name[ 20] ; ; struct date birthday; { struct stutype * ps, stu1; char temp[ 20] ; ps = &stu1; printf( " Input name, year, month, day of birthday: \ n" ) ; gets( ps - > name) ; gets( temp) ; ps - > birthday. year = atoi( temp) ; gets( temp) ; ps - > birthday. month = atoi( temp) ;
264 gets( temp) ; ps - > birthday. day = atoi( temp) ; printf ( " \noutput name,, year, month, day of birthday \n" ) ; printf ( " % s % d / % d / % d \ n ", ps - > name, ps - > birthday. year, ps - > birthday. month, ps - > birthday. day) ; stu1, ps stu1, temp[ 20 ], atoi( ),, : stu_1. name ( * ps). name ps - > name ( ) 2 ) ( ),,,,,,, 6. 48, 588 #include < stdlib. h > #define N 40 typedef struct stud_type { char name[ 20] ; STU; int age; float score; { STU input( int n) ; void listofstu( STU * ps, int count) ; STU stu[ N], * ptr; int k, x; printf( " input the person sum: " ) ; scanf( " % d", &x) ; for ( k = 0; k < x; k + + ) stu[ k] = input( k) ; listofstu( stu, x) ; / / ptr = &stu[ 0 ] ; listofstu( ptr, x) ; 251
265 252 STU input( int n) { STU sx; char in_buf[ 20] ; printf ( " \ninput name, age, score of stu[ % d] : \ n", n) ; gets( sx. name) ; gets( in_buf) ; sx. age = atoi( in_buf) ; gets( in_buf) ; sx. score = atof( in_buf) ; return sx; void listofstu( STU * ps, int count) { int k, sum = 0; for ( k = 0; k < count; k + + ) { if( ps - > score > 588) { sum + + ; printf( " Student: % s, % d, % f \ n ", ps - > name, ps - > age, ps - > score) ; ps + + ; printf( " the person sum = % d", sum) ; , C, : union {
266 ; : union perdata { int mclass; char dept[ 20] ; ; perdata, mclass dept, perdata, 22, 20 perdata mclass MC MC dept,,,,,,, perdata dept 20, mclass MC mm, nn union data { int a; float b; double c; char d; mm ; struct stud { int a; float b; double c; char d; nn ; void main ( ) { printf( " % d, % d", sizeof( struct stud), sizeof( union data) ) ; : 1 5, 8 253
267 ( 1), union perdata { int mclass; char dept[ 20 ] ; un_1, un_2 ; ( 2) typedef { int mclass; union perdata char dept[ 20] ; UNPERDATA; UNPERDATA un_1, un_2 ; :. : un_1. mclass un_1. dept ( ) : un_1 = un_2 gets( un_1),,, union perdata { int mclass; char dept[ 20] ; un_1, un_2 ; { un_1. mclass = 65 ; printf( mclass \ t dept ) ; printf( " % d \t", un_1. mclass) ; printf( " % s", un_1. dept) ; gets( un_1. dept) ; printf( " % d \t", un_1. mclass) ; printf( " % s \ n", un_1. dept) ;
268 soft, : mclass 65 A dept soft mclass 65, ASCII A, dept, dept mclass, A, dept soft, mclass ( 16 ) , 3 3 4, / / S 1405 S 1407 T T 255 struct { char name[ 20] ; char courses[ 20] ; char flag; union { int mclass; depa; body[ 4 ] ; { int i; char dept[ 20] ; char flag; for( i = 0 ; i < 4; i + + ) { printf( " input name, courses, flag, class or dept \ n" ) ; gets ( body[ i]. name) ; gets ( body[ i]. courses) ; body [ i]. flag = getchar( ) ; if ( body[ i]. flag = = s ) else scanf( " % d", &body[ i]. depa. mclass) ;
269 256 getchar( ) ; gets( body[ i]. depa. dept) ; printf( " output techeres and students report \n" ) ; for( i = 0 ; i < 4; i + + ) { if ( body[ i]. flag = = s ) else printf ( " % s \ t% s \ t% d \n", body[ i]. name, body[ i]. courses, body[ i]. depa. mclass) ; printf ( " % s \ t% s \ t% s \ n", body[ i]. name, body[ i]. courses, body[ i]. depa. dept) ; body, 4 depa, 2, mclass, ; dept,, flag,, s, 1 for,, 3 name, courses flag, flag, " s" depa. mclass ( ), depa. dept ( ) 2 for, flag, 2, :,,,,,,,, union un { float f; int b; char d; u = {1. 8, 45, G ; ( 4), union keybord { unsigned char ch[ 2] ;
270 key; unsigned int i; ch[ 1] ch[ 0] key, ch[ 0] 8, ch[ 1] 8, :, 16, 8 0, ASCII ; 8 0, 8, : 0x48 0x50 0x46 d( IBM PC ), bioskey, bios. h, bios. h, bioskey 2, : 0, ; 1,, 0 #include < bios. h > #include < stdlib. h > union keybord { unsigned char ch[ 2] ; unsigned int i; key; { for( ; ; ) { printf( " \npress ESC key for exit to OS! \ n" ) ; while(! bioskey( 1) ) ; key. i = bioskey( 0) ; if ( key. ch[ 0]! = 0) { if ( key. ch[ 0] = = 0x1 b) else else exit( 0 ) ; printf( " \ nyou pressed the % c key! \n", key. ch[ 0] ) ; 257
271 switch( key. ch[ 1 ] ) { case 0x48: printf( " \nyou pressed the % c key! \n", 24) ; case 0x50: case 0x46: case 0x4d: break; printf( " \nyou pressed the % c key! \n", 25) ; break; printf( " \nyou pressed the % c key! \n", 27) ; break; printf( " \ nyou pressed the % c key! \ n", 26) ; break; ,, male female2 ; 7 Mon, Tues, Wed, Thurs, Fri, Sat, Sun ; 1 12,,, C,,,, : enum { ;, : enum weekday{ sun, mon, tue, wed, thu, fri, sat ; weekday, 7, 1 7 weekday 7
272 a, b, c;, 3 2 ( 1), typedef enum weekday{ sun, mon, tue, wed, thu, fri, sat WEEKTYPE; WEEKTYPE ( 2), enum weekday{ sun, mon, tue, wed, thu, fri, sat a, b, c; a, b, c, : a = mon; c = sun;, : a = a + 1; c + + ; :,, enum weekday : sun = 5; mon = 2 ; weekday. sun = mon;, 0 0, 1, 2 enum weekday, sun 0, mon 1,, sat 6 : enum weekday{ sun = 7, mon = 1, tud, wed, thu, fri, sat workday; sun 7, mon 1, tud sat 2 6, : a = sum; b = mon; ; a = 0; b = 1;, : a = ( enum weekday) 2; 2 a, : a = tue;,, enum year{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ; enum year { Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec ; { enum color{ RED, YELLOW, GREENmcolor; 259
273 260 printf( " ( % d) RED, ( % d) YELLOW, ( % d) GREEN \n", RED, YELLOW, GREEN) ; printf( " Input color: " ) ; scanf( " % d", &mcolor) ; switch( mcolor) { case RED: printf( " Red color \n" ) ; break; case YELLOW: printf( " Yellow color \n" ) ; break; case GREEN: printf( " Green color \ n" ) ; break; default: printf( " No color color \ n" ) ; break;,, switch - case, bush, jack, rose, kenya, 1 15 { enum body{ bush, jack, rose, kenya month[ 26], j; int i; j = bush; for ( i = 1 ; i < = 15; i + + ) { month[ i] = j; j + + ; if ( j > kenya) j = bush; for( i = 1 ; i < = 15; i + + ) switch( month[ i] ) { case bush: printf( " % 2d % s \ n", i, " bush" ) ; break; case jack: printf( " % 2d % s \ n", i, " jack" ) ; break; case rose: printf( " % 2d % s \ n", i, " rose" ) ; break; case kenya: printf( " % 2d % s \ n", i, " kenya" ) ; break;
274 SIZE, n( 3 ), n, n 6. 2,, 6. 3 : : 1, 3, 0, 3, ,, 1, 6. 5 n, :,, n , 1 6, 6, ( 60 ), % % % % % % 6. 7, : ( ) 6. 9, ( ) 6. 10,,,,,, , , 10, 9 9 ( 9, 0 ) ( 8 )
275 262 5, 5, n, m,,,,, ( 4, : 1289) : int FindMostWord( char * s, int n) ; : s ( ) n : Find- MostWord( The function is many functional module., 3 ) ; ASCII : 2 abcd abcfe, ,, 6. 18,, :, :, :,, : ; :,, : 0 a,, 9 j, n, 2 1 n n, 2 ( strcat) :, 2, N, number, name, score [ 5],, (,,,, ) 5, 12 : ( 1), ( 2),,, ( 3)
276 C, C ( int) ( char),, ( bit) : : 00, 01, 10, : 000, 001, 010, 011, 100, 101, 110, : ,, n 2 n ( byte) :, 8, LSB, MSB , 1
277 , 2, 4, , 1 1 ),, 1 2 8, ) 264 1, bit7, bit6 bit0 2, bit15, bit14 bit0 : 0, 1 :, ( 1) : + 7 : : ( 2) : + 7 : / * 0 * / - 7 : / * 1* / ( 3) : 1, : + 7 : : : : ( 4),,,,, : 0 11, = 12 n 0 2 n - 1, = 2 n
278 ,,, 12, 8 4, 4, 8, 8 4, n, n = 8, , ( 9 ), 8, 1, , 8 2 8,, n, x : : : 1,, 1 : + 7 : : ) :, N = S 10 j 0 < s < 10, : N = S 2 j 0 < s < 2 J ( ), 2, 0 < s < 2 32 : N, 8 M, 23 R = 1. M 2 ( N ) 4 ) C, 3, 7 = ( 111 ) 2 ; 4, 8 = ( 1000 ) 2, 15 = ( 1111) 2 C :, 6, A B C D E F ( a f
279 ) ; 0x, 12, 12 0xC; 0xFF 16 1 C scanf( ) printf( ) o, x,, 0x5A, : 5 A C 6 : & < < > > :,, :, 1, 1, 0 : x = y = & x&y = { unsigned int x, y; printf( " Input x and y: " ) ; scanf( " % x, % x", &x, &y) ; printf( " x&y = % x \ n", x&y) ;, 89, ee, x&y = 88 :
280 ( 1) :, : x&0 = & ( 2) x :, : x, 1, x x : unsigned x = 0xAE x 4 : x&0xf & x bit2 bit4 bit6 : x&0x & : 2, 1, 1, 0 unsigned x = 0x89; Y = 0xEE x y = 0xEF 7. 2 { unsigned int x, y; printf( " Input x and y: " ) ; scanf( " % x, % x", &x, &y) ; printf( " x y = % x \ n", x y) ;, 89, ee, x y = EF : 1 :, : x 1
281 , 1, x x 1, : unsigned x = 0 xa0, 4 1 x 0xF = 0xAF : 2, ( ), 1, 0 : unsigned x = 0 x89; y = 0xEE x^y = 0x { unsigned int x, y; printf( " Input x and y: " ) ; scanf( " % x, % x", &x, &y) ; printf( " x^y = % x\ n", x^y) ;, 89, ee, x^y = 67 : :, : x, 1, x : unsigned x = 0 xae, x 4 : x^0x0f = 0xA , : , : a = a^b; b = b^a; a = a^b; 2 a,
282 b :, 0 1, 1 0 : : 7. 4 { unsigned int x; printf( " Input x: " ) ; scanf( " % x", &x) ; printf( " x = % x \n", x) ;, F8, x = FF07 : int 16, 00 FF : = + 1 0, 1 a, : a & : (, 0 ) 1,, 2, n 2 n : a = a < < 2 a 2, { unsigned int x, n; printf( " \ ninput x: " ) ; scanf( " % u", &x) ; printf( " Input number to move: " ) ; scanf( " % u", &n) ;
283 printf( " x < < % u = % u \ n", n, x < < n) ;, 128, 2, x < < 2 = 512 : ( : 128) x < < ( : 512) : 128, 9,, x < < 9 = 0 : ( : 128) x < < ( : 0, 1 ) : ( 0 / 1, ), 2, 2, n 2 n,,, : a = a > > 2 a { int x, n; printf( " \ ninput x: " ) ; scanf( " % d", &x) ; printf( " Input number to move: " ) ; scanf( " % d", &n) ; printf( " x > > % d = % d \ n", n, x > > n) ;, 128, 2, x > > 2 = 32 : ( : 128) x > > ( : 32) - 128, 2, x > > 2 = - 32 : ( : ) ( : ) ( : - 128, )
284 x > > ( : - 32, ) ( : - 32 ) ( : - 32 ) ( : - 32) :,, 0, C : & =, : a& = b a = a&b =, : a = b a = a b > > =, : a > > = b a = a > > b < < =, : a < < = b a = a < < b =, : a = b a = a b int num, 8 11 ( 0 ) ( 1) : num 8, num ( 2) : { int num, mask; printf( " Input a integer number: " ) ; scanf( " % d", &num) ; num > > = 8; mask = ( 0 < < 4) ; printf( " result = 0x% x \ n", num & mask) ;
285 272 : ( 0 < < 4) 0, 1; 4, 4 0, 1;, 4 1, ( 1) : 1 int num, ( ) mask = 1 < < 15 i 1 num&mask ( ), 0, 1 num 1, i% 4 0, 4 i < = 16, ( 2) : #include " stdio. h" { int num, mask, i; printf( " Input a integer number: " ) ; scanf( " % d", &num) ; mask = 1 < < 15; printf( " % d = ", num) ; for( i = 1; i < = 16; i + + ) { putchar( num&mask? 1 : 0 ) ; putchar(, ) ; printf( " B\ n" ) ; 7. 9 num < < = 1; if( i% 4 = = 0) a, > , > >, > > 0 1 ( 1) : ( ), n a n b n ( 16 - n ) b = a < < ( 16 - n) ;
286 a n, n 0 c = a > > n; c b c = a b ( 2) : { unsigned a, b, c; int n; printf( " \ ninput a number and move: " ) ; scanf( " % x% d", &a, &n) ; b = a < < ( 16 - n) ; c = a > > n; c = c b; printf( " % x \ n% x", a, c) ; C, C ( 1) : a ( 16 - n), n b n, 0 : b = a < < ( 16 - n) ; a n : a > > n; a b a, : a = b; 273 ( 2) :
287 274 #include < ctype. h > { unsigned rrmove( unsigned int a, int n) ; unsigned lrmove( unsigned int a, int n) ; unsigned int a, b; int n; char dir; printf( " \ nnnumber to be moved: " ) ; scanf( " % x", &a) ; printf( " Count to move: " ) ; scanf( " % d", &n) ; printf( " Direction( R / L) : " ) ; getchar( ) ; dir = toupper( getchar( ) ) ; if( dir = = R ) b = rrmove( a, n) ; else b = lrmove( a, n) ; printf( " % c move result: % x \n", dir, b) ; unsigned rrmove( unsigned int a, int n) { unsigned int b; b = a < < ( 16 - n) ; a > > = n; a = b; return a; unsigned lrmove( unsigned a, int n) { unsigned b; b = a > > ( 16 - n) ; a < < = n; a = b; return a;
288 C,,,, ( int) ( unsigned int) : struct { ;,, : 275 bit5 bit0 : 0 CPU, 1 PC: Precision Control,, ( ) : 00: 24 ( ) 01: 10: 53 ( ) 11: 64 ( ) RC: Rounding Control, : 00, ( ) 01: 10: 11: C,,, struct FPU { unsigned : 4; / *, 4 * / unsigned RC: 2 / * RC, 2 * / unsigned PC: 2; unsigned : 2; / *, 2 * / unsigned PM: 1; / * PM, 1 * / unsigned UM: 1;
289 unsigned OM: 1; unsigned ZM: 1; unsigned DM: 1; unsigned IM: 1; ;, struct packed_data { unsigned ord: 2 ; unsigned coll: 6; unsigned adjust: 4; unsigned check: 4; int dat; data; data ord coll adjust check dat : PC,, 2, : struct bs { unsigned a: 4 unsigned : 0 / * * / unsigned b: 4 / * * / unsigned c: 4, a 1 4, 4 0 ; b 2, 4 ; c 4,, 8, : struct k { int a: 1 int : 2 /* 2 * / int b: 3 int c: 2 ;,,
290 ,, : unsigned b: 1; struct control { int x; ; : char name[ 8 ] ; unsigned a: 3 ; unsigned : 0 ; unsigned c: 3 ; struct control control_var;, a b c : control_ var. a control _var. b control_var. c, control_var. a 3, 7 :,, ( ),,, n, 0 ( 2 n - 1) % d % x % u % o,,, { struct bs { unsigned a: 1; unsigned b: 3; unsigned c: 4; bit, * pbit; bit. a = 1 ; bit. b = 7; bit. c = 15; 277
291 printf( " % d, % d, % d \ n", bit. a, bit. b, bit. c) ; pbit = &bit; pbit - > a = 0; pbit - > b& = 3; pbit - > c = 1; printf( " % d, % d, % d \ n", pbit - > a, pbit - > b, pbit - > c) ; : 1, 7, 15 0, 3, bs, 3 a, b, c bs bit bs pbit 3 ( ) 3 : bit pbit; a 0; " & = ", pbit - > b = pbit - > b&3, b 7, 3 3( 111&011 = 011, 3) ;, " = ", c 15( pbit - > c = pbit - > c 1) 3,, : struct control * ptr, var_data; ptr = &var_data; printf( % d \n, ptr - > c) ; / * var_data. c * /,, : &var_data. a , : void displaybits( unsigned x) ; 7. 2, 4, ( displaybits( ) ), power2 ( int number, int pow), : number* 2 p ow,
292 , 2, packcharacters PackCharacters : 1, 8, unpackcharacters, 2, : 0xFF00( 65280),, 8, 1 ; 0x00FF( 255), 8, ,, 7. 7, ( : 0xF9 ),, ( : 0xF9 ) encrypt( char * word, char code) ; : * word, code 7. 8 : unsigned getbits( unsigned value, int start, int end) ; start, end : getbits( 0xFE56, 5, 8) ; 0xFE : unsigned extracteoddbits( unsigned x) ; : unsigned unmutexcode( unsigned value) ; value 1, value, 1; : 16, : 16,, 279
293 ;,,,, :, ;, , : ( 1)
294 , : 1024, 4, ,, ( ) ASCII, ASCII : 127, ( ASCII ) 3 : ASCII,, ( ) ( 2) C, C,,,,,,,, C ( 3),,, C,, C : KYBD: SCRN: PRN LPT1 : 3,, 3 : stdin: stdout: stderr: ; ; ; 3,, C,, ( ) C 281
295 , C, ( 4),,,, UNIX, 1983 ANSI C, ,,,, FILE Turbo C stdio. h FILE : / * Definition of the control structure for streams* / typedef struct { int level; / * fill / empty level of buffer * / unsigned flags; / * File status flags * / char fd; / * File descriptor * / unsigned char hold; / * Ungetc char if no buffer * / int bsize; / * Buffer size * / unsigned char * buffer; / * Data transfer buffer * / unsigned char * curp; / * Current active pointer * / unsigned istemp; / * Temporary file indicator * / short token; / * Used for validity checking * / FILE; / * This is the FILE object * /, / FILE, C,,
296 FILE (, ), /,,,,, : FILE * fp1, * fp2,, * fpn; / * * / FILE fp1, fp2,, fpn, FILE, : :, : : : ( 1) / ; ( 2) ; ( 3) C ( ANSI C) fopen / fopen : FILE * fpt; /* fpt* / fpt = fopen( file_name, file_mode) ; : fpt, ; file_name, ; file_mode /, file _ mode : r ; w ; a,,
297 284 rb wb ab r + ;, ; ; ; / ; ; w + ; a +,, ;, ; rb + ; wb + ; ab + / fopen,, fopen, NULL, : if( ( fpt = fopen( file_name, file_mode) ) = = NULL) { printf( Can t open this file! exit( 0) ;, : #include < stdlib. h > { FILE * fpt; \ n ) ; if( ( fpt = fopen( file1. txt, r ) ) = = NULL) { printf( Can t open this file! exit( 0) \ n ) ; : file1. txt, fpt ;, fpt NULL, exit( 0 ), ;,
298 , 2 :,,,,, ( ), C fclose : fclose( ) ; :,, fclose, 0, fclose fclose( fp),, ) fgetc : ch = fgetc( fpt) ; : fpt, ch fgetc, EOF( - 1 ) fpt stdin, fgetc ( stdin), getchar( ) fgetc : fgetc,
299 286, fgetc( fp) ;,,, fgetc, ( fgetc ) fgetc,,,,,,,, 8. 1 ( 1) : ex8-1. cpp fp ex8-1. cpp, fp, 1 While(! = ) ( 2) : / * ex8-1. cpp * / #include < stdlib. h > { FILE * fp; char ch; if( ( fp = fopen( " ex8-1. cpp", " r" ) ) = = NULL) { printf( " Can t open file ex8-1. cpp! \ n" ) ; exit( 0) ; ch = fgetc( fp) ; / * * / while( ch! = EOF) /* * / { putchar( ch) ; / * putchar( ) * / ch = fgetc( fp) ; / * * / fclose( fp) ; / * fclose( ) * /, EOF( - 1), ASCII - 1 ;
300 ,, - 1, ANSI C feof( pf), feof, feof feof / * ex8-2. cpp * / #include < stdlib. h > { FILE * fp; char ch; if( ( fp = fopen( " ex8-2. cpp", " r" ) ) = = NULL) { printf( " Can t open file ex8-2. cpp! \ n" ) ; exit( 0) ; ch = fgetc( fp) ; while(! feof( fp) ) / * feof( ) * / { putchar( ch) ; fclose( fp) ; ch = fgetc( fp) ; ) fputc : fputc( ch, fpt) ; : ch fpt fputc, EOF( - 1 ) fpt stdout, fputc ( stdout), putchar( ) fputc :,,,,, fputc,, EOF 8. 3 mydata, #,
301 288 ( 1) : FILE fp w mydata, fp mydata,,, do while, mydata, # while ( EOF),, ( 2) : / * ex8-3. cpp* / #include < stdlib. h > { FILE * fp; char ch; if( ( fp = fopen( mydata, w ) ) = = NULL) { printf( Can t create file mydata! exit( 0 ) ; printf( " input a string: \n" ) ; do \ n ) ; { ch = getchar( ) ; / * * / fputc( ch, fp) ; / * test. txt* / while( ch! = EOF) ; / * * / fclose( fp) ; / * * / fp = fopen( mydata, r ) ; / * r mydata * / ch = fgetc( fp) ; while( ch! { putchar( ch) ; ch = fgetc( fp) ; printf( " \ n" ) ; fclose( fp) ; = EOF) 3 ) C ( Turbo C )
302 ( ) putw getw putw(, fp) fp getw( fp) fp, 8. 4 putw 2 / * ex8-4. cpp * / #include < stdlib. h > { union { char c[ 2] ; int x; ch; FILE * fp; if( ( fp = fopen( " test. dat", " w" ) ) = = NULL) { printf( " Can t create file! \ n" ) ; exit( 0) ; ch. c[ 0] = getchar( ) ; getchar( ) ; / * getchar * / ch. c[ 1] = getchar( ) ; putw( ch. x, fp) ; fclose( fp) ; ) 8. 5 ( ) / * ex8-5. cpp * / #include < stdlib. h > void main( int argc, char * argv[ ] ) { FILE * fpt; int count = 0 ; if( argc < 2) { printf( " File name unknown! \n" ) ; exit( 0) ; if( ( fpt = fopen( argv[ 1 ], " r" ) ) = = NULL) { printf( " Can t open file data. txt! \ n" ) ;
303 290 exit( 0) ; while( fgetc( fpt)! count + + ; fclose( fpt) ; printf( " File = EOF), fgetc( fpt)! % s contains % d characters. \ n", argv[ 1], count) ; 8. 6 = EOF :, ( ) / * ex8-6. cpp * / #include < stdlib. h > void main( int argc, char * argv[ ] ) { FILE * fpt; int count = 0 ; / * * / int space = 1; /* * / char ch; if( argc < 2) { printf( " File name unknown! \n" ) ; exit( 0) ; if( ( fpt = fopen( argv[ 1 ], " r" ) ) = = NULL) { printf( " Can t open file data. txt! \ n" ) ; exit( 0) ; while( ( ch = fgetc( fpt) )! switch( ch) { case : fclose( fpt) ; printf( " File case case default: \ t : = EOF) \ n : space + + ; break; if( space) { space = 0; count + + ; % s contains % d words. \ n", argv[ 1], count) ;
304 8. 7 / * ex8-7. cpp * / #include < stdlib. h > void main( int argc, char * argv[ ] ) { FILE * in, * out; char ch; if( argc! = 3) { printf( " You forgot to enter a filename. \n" ) ; exit( 0) ; if( ( in = fopen( argv[ 1 ], " rb" ) ) = = NULL) { printf( " Cannot open in_file. \ n" ) ; exit( 0) ; if( ( out = fopen( argv[ 2], " wb" ) ) = = NULL) { printf( " Cannot open out_file. \ n" ) ; exit( 0) ; while( 1) { ch = fgetc( in) ; if(! feof( in) ) fputc( ch, out) ; else break; fclose( in) ; fclose( out) ; ) fputs : fputs( string, fpt) : string ( ) fpt fputs
305 ( 1) :, EOF( - 1) stdout, puts, \0 : fputs \ 0 ; puts myfile. txt 6 10 FILE fp w myfile. txt, fp myfile. txt,,, for 6 6,, fputc( \ n, fp) / * ex8-8. cpp * / #include < stdlib. h > { FILE * fp; int i; char s[ 10 ] ; if( ( fp = fopen( " myfile. txt", " w" ) ) = = NULL) { printf( " error" ) ; exit( 0) ; printf( " enter string: \ n" ) ; for( i = 1; i < = 6; i + + ) { scanf( " % s", s) ; fclose( fp) ; fputs( s, fp) ; fputc( \n, fp) ; 2 ) fgets : fgets( string, n, fpt) ; : fpt n - 1, string n - 1 \ n EOF,, \ 0 fgets string
306 8. 9, NULL stdin, gets, \ n : fgets, \0 ; gets \0,, abc. txt, # abc. txt / * ex8-9. cpp * / #include < stdlib. h > #include < string. h > { FILE * fp; char str[ 80] ; int i = 0; if( ( fp = fopen( " abc. txt", " w" ) ) = = NULL) { printf( " can t open file \n" ) ; exit( 0) ; printf( " Enter a string: \ n" ) ; gets( str) ; while( str[ i]! = # ) { if( str[ i] > = a &&str[ i] < = z ) str[ i] = str[ i] - 32; fputc( str[ i], fp) ; i + + ; fclose( fp) ; fp = fopen( " abc. txt", " r" ) ; fgets( str, strlen( str) + 1, fp) ; printf( " % s \ n", str) ; fclose( fp) ; 293
307 ) fscanf 294 : fscanf( fpt,, ) ; : ASCII fpt, scanf, ( ) ( ) stdin, scanf test. dat, / * ex8-10. cpp * / #include < stdlib. h > { char str[ 80] ; int x; FILE * fpt; if( ( fpt = fopen( test. dat, r ) ) = = NULL) { puts( Can t open file. \n ) ; exit( 0) ; while( fscanf( fpt, % s % d, str, &x)! = EOF) printf( % s % d \n, str, x) ; fclose( fpt) ; 2 ) fprintf : fprintf( fpt,, ) ; : ASCII fpt fpt stdout, printf / * ex8-11. cpp * /
308 #include < stdlib. h > #include < string. h > { FILE * fpt; int num; char name[ 10] ; float score; if( ( fpt = fopen( score. dat, w ) ) = = NULL) { puts( Can t create file. \n ) ; exit( 0) ; printf( " Input name, number, score: " ) ; scanf( " % s % d % f", name, &num, &score) ; while( strlen( name)! = 0) { fprintf( fpt, " % s % d % f", name, num, score) ; printf( " Input name, number, score: " ) ; scanf( " % s % d % f", name, &num, &score) ; fclose( fpt) ; ) fwrite : fwrite( buffer, size, count, fpt) ; : buffer ; size ; count size ; fpt : buffer count size ( count* size ) fpt, n( n < 100) emp, :,,,, ( 1) :,,,, ; fp;
309 296 if( emp ) { ; ; n; n n ; n fwrite fp emp ; fp ( 2) : / * ex8-12. cpp * / #include < stdlib. h > #define num 100 static struct employee { char no[ 5] ; char name[ 10] ; char sex[ 3] ; int age; int salar; emp[ num] ; { FILE * fp; int n, i; char inbuf[ 20] ; if( ( fp = fopen( " emp", " wb" ) ) = = NULL) { printf( " can t create file emp \ n" ) ; exit( 0) ; printf( " Input emp number: \ n" ) ; scanf( " % d", &n) ; printf( " : < enter > \ n" ) ; for( i = 0; i < n; i + + ) { printf( " % d : ", i + 1) ; gets( emp[ i]. no) ; gets( emp[ i]. name) ; gets( emp[ i]. sex) ; gets( inbuf) ; emp[ i]. age = atoi( inbuf) ; gets( inbuf) ;
310 emp[ i]. salar = atoi( inbuf) ; for( i = 0; i < n; i + + ) fwrite( &emp[ i], sizeof( struct employee), 1, fp) ; fclose( fp) ; : Input emp number: 3 : < enter > 1 : 1 zhangli m : 2 wangwu f : 3 lisi m ) fread : fread( buffer, size, count, fpt) ; : buffer ; size ; count size ; fpt : fpt count size ( count* size ) buffer, emp / * ex8-13. cpp * / #include < stdlib. h > #define num 100 static struct employee { char no[ 5] ; char name[ 10] ; char sex[ 3] ; int age; int salar; emp[ num] ; { FILE * fp; int i = 0; if( ( fp = fopen( " emp", " r" ) ) = = NULL) 297
311 298 { printf( " can t open file emp \n" ) ; exit( 0) ; printf( \ n ) ; while( 1) { fread( &emp[ i], sizeof( struct employee), 1, fp) ; printf( " % - 9s% - 9s% - 9s% - 8d% - 8d \n", emp[ i]. no, emp[ i]. name, emp[ i]. sex, emp[ i]. age, emp[ i]. salar) ; i = i + 1; fclose( fp) ; if( feof( fp) ) break; : 1 zhangli m wangwu f lisi m ,, ( ; ),,, rewind ftell fseek 1 ) rewind : rewind( fpt) ; :
312 / * ex8-14. cpp* / #include < stdlib. h > { FILE * fp; char ch; if( ( fp = fopen( mydata, w + ) ) = = NULL) { printf( Can t create file mydata! exit( 0) ; printf( " input a string: \n" ) ; do \n ) ; { ch = getchar( ) ; / * * / fputc( ch, fp) ; / * mydata * / while( ch! = EOF) ; / * * / rewind( fp) / * * / ch = fgetc( fp) ; while( ch! = EOF) { putchar( ch) ; ch = fgetc( fp) ; printf( " \ n" ) ; fclose( fp) ; ) ftell : ftell( fpt) ; :,, - 1L emp / * ex8-15. cpp * / #include < stdlib. h > viod main( ) { FILE * fp; int i; if( ( fp = fopen( " emp", " r" ) ) = = NULL) { printf( " can t open file emp" ) ;
313 exit( 0) ; fseek( fp, 0, SEEK_END) ; / * * / printf( " emp length is: % ldbyte \ n", ftell( fp) ) ; fclose( fp) ; 3 ) fseek 300 : fseek( fpt, offset, from) ; : fpt ; offset,, ; from, : SEEK_SET 0 SEEK_CUR 1 SEEK_END 2 : from offset ( offset, offset ) : fseek( fp, 80 L, 0) ;, 80 : fseek( fp, 40L, 1) ; 40 : fseek( fp, - 40L, 2) ;, C, C, 3 : ; fseek ; fread emp 1500 / * ex8-16. cpp * /
314 #include < stdlib. h > { FILE * fp; static struct employee { char no[ 5] ; emp; int i = 0; char name[ 10] ; char sex[ 3] ; int age; int salar; if( ( fp = fopen( " emp", " rb" ) ) = = NULL) { printf( " can t open file emp \n" ) ; exit( 0) ; printf( \ n ) ; while( 1) { fseek( fp, i* sizeof( struct employee), 0) ; fread( &emp, sizeof( struct employee), 1, fp) ; if( feof( fp) ) break; if( emp. salar > 1500) printf( " % - 9s% - 9s% - 9s% - 8d% - 8 d \ n", emp. no, emp. name, i = i + 1; emp. sex, emp. age, emp. salar) ; fclose( fp) ; C, I / O, fgets NULL, 2,,, C
315 ferror : ferror( fpt) ; : I /O, ferror ferror ( 0), ; ferror ( 0), I / O ferror, I / O, fopen, ferror clearerr 302 : clearerr( fpt) ; : ( 1) C,, ( 2) fopen( " test", " w + " ), test, ( 3) fputs( buff, stdout) ( 4) ab. txt, fopen( " ab. txt", " r + " ) ( 5) feof( fp) ( 6 ) : fread ( buffer, size, count, fpt ) ; buffer ( 7) : fgets( buffer, n, fp) ; fp buffer ( 8) : main( ) { FILE * fp; char str1[ ] = thank you ; fp = fopen( PRN, w ) ; fputs( str1, fp) ;
316 fclose( fp) ; ( 9) #include < stdlib. h > main( ) { FILE * fp; if( ( fp = fopen( " test", " w" ) ) = = NULL) { printf( " Can t create file \n" ) ; exit( 0) ; for( i = 1; i < = 10 ; i + + ) fprintf( fp, " % 3d", i) ; for( i = o; i < 10; i + + ) { fseek( fp, i* 3L, SEEK_SET) ; fscanf( fp, " % d", &n) ; printf( " % 3 d", n) ; fclose( fp) ; ( 10) : struct stu{ char name[ 10] ; char sex[ 2] ; int telephone; char addr[ 20 ] ; student[ 40] ; student, fp, fwrite( student,, 1, fp) ; 8. 2 ( 1) ( ) A. B. C. D. ( 2) ( ) A. B. C. D. 303
317 304 ( 3) fopen 1 ( ) A. d: myfile \ test. txt B. d: \ myfile \abc. txt C. " d: \ myfile \ a. txt" D. " d: \ \ myfile \ \ mydata. txt" ( 4) fopen, ( ) A. B. 0 C. 1 D. error ( 5) fopen,, ( ) A. ab + B. wb C. rb + D. ab ( 6), fclose ( ) A. - 1 B. TRUE C. 0 D. 1 ( 7) feof, ( ) A. EOF B. 1 C. 0 D. ( 8) fseek ( ) A. B. C. D. ( 9) fgetc, ( ) A. B. C. D. B C ( 10) : fwrite( buffer, size, count, fp) ; buffer ( ) A., B., C., D., ( 11), : test abc xyz ( b) /* filename test. cpp* / main( int argc, char * argv[ ] ) { FILE * fp1, fp2; if( argc < 3) { printf( " Usage: test filename1 filename2 \ n" ) ; exit( 0 ) ; fp1 = fopen( argv[ 1], " r" ) ; fp2 = fopen( arg[ 2 ], " w" ) ; while(! feof( fp1 ) ) fputc( fgetc( fp1), fp2) ;
318 fclose( fp1) ; fclose( fp2) ; A. xyz abc B. abc xyz C. abc xyz, abc D. xyz abc, xyz ( 12), test ( ) #include < stdlib. h > main( ) { FILE * fpt; char * s1 = thank ; char * s2 = you ; if( ( fpt = fopen( test. txt, w + ) ) = = NULL) { printf( Can t open file test \ n ) ; exit( 0 ) ; fwrite( s1, 5, 1, fpt) ; fseek( fpt, 0l, SEEK_SET) ; fwrite( s2, 3, 1, fpt) ; fclose( fpt) ; A. thank B. you C. D. younk ( 13) fopen file_mode r w, ( ) A. r, w B. r, w C. r, w D., r, w ( 14) fread( buff, 64, 2, fp1) ( ) A. fp 64 2, buf B. fp 2 64, buf C. fp 2 64, buf D. fp 64 2, buf 305
319 ( 1)?? ( 2)?? ( 3)? 8. 4 ( 1),, ( 2) 3,, ( 3) Fprint fscanf ( 4) 3,, ( 0, 1, 2), ( 5) cos 2* x /32( x = 0, 1, 2,, 32 ), result. txt ( 6) ( ) ( 7) 2 file1 file2,, 2 ( ), file3 ( 8),, test,! ( 9) 5, ( ), stud 3 ( 10) stud stud_sort ( 11) file1. c file2. c ( 12) mydata ( 13), ( 14) test. dat,
320 C C, :,, 2, ;, C 1 ) C C,, ( ), : struct test { char ch; struct test * next; /* next struct test * /
321 308 ;,, : struct test { char ch; struct test next; /* next struct test * / ; 2,, 2 : struct A { int x; struct B * pb; /* pb struct B * / ; struct B { int y; struct A * pa; /* pa struct A * / ; 9. 1 { struct B; /* struct B, * / struct A { int x; struct B * pb; a = {100, NULL ; struct B { int y; struct A * pa; b = {500, NULL ; a. pb = &b; b. pa = &a; printf( " % d \ n", b. pa - > x) ; printf( " % d \ n", a. pb - > y) ; a pb b, a. pb - > y b y b pa a, b. pa - > x a
322 C x 2 ) C, C stdlib. h alloc. h, 2, malloc realloc free 3 ( 1) malloc : void * malloc( unsigned int size) ; : size, ( ) void( ),, NULL ( 2) free : void free( void * ptr) ; : ptr, 9. 2, #include < string. h > #include < stdlib. h > { int num, i; char inbuf[ 100], * * strs; printf( " Enter the number of string for input: " ) ; scanf( " % d", &num) ; getchar( ) ; strs = ( char * * ) malloc( num* sizeof( char * ) ) ; for( i = 0 ; i < num; i + + ) { gets( inbuf) ; strs[ i] = ( char * ) malloc( strlen( inbuf) + 1) ; strcpy( strs[ i], inbuf) ; for( i = 0 ; i < num; i + + ) puts( strs[ i] ) ; strs = ( char * * ) malloc( num* sizeof( char * ) ) ; num, strs, strs 309
323 310, strs[ i] = ( char * ) malloc( strlen( inbuf) + 1 ) ;, i strs[ i], 9. 1 ( 3) realloc : void * realloc( void * ptr, unsigned int newsize) ; : ptr newsize, ptr, ; 9. 1 ptr, 9. 3, #include < string. h > #include < stdlib. h > { char inbuf[ 100], * strp; printf( " Enter several strings, null line for end. \ n" ) ; gets( inbuf) ; strp = ( char * ) malloc( strlen( inbuf) + 1) ; strcpy( strp, inbuf) ; while( strlen( gets( inbuf) ) ) { strp = ( char * ) realloc( strp, strlen( strp) + strlen( inbuf) + 1) ; strcat( strp, inbuf) ; puts( strp) ;, strcpy strp, realloc strp strlen( strp) + strlen ( inbuf) + 1,, ( )
324 C ,,, 2 :,, :, ; 1 ;,, : ; ; ; ; ; ; ; ; ;,,, ( ),, ), ;, ( 1) C,,, 9. 2, 1 ( 0 ) ( M),
325 312 : LOC( i) = LOC( 0) + i * M ( 2) : ; 9. 2,, ; ; : #define N 100 typedef struct stu { char name[ 20] ; float score; STU; STU stu[ N] ; int n = 0; : int insertlist( int i, STU x) / * i x * / { int j; if( n > = N) { printf( " overflow! " ) ; getch( ) ; return - 1; if( i < 0 i > n) { printf( " out of range! " ) ; getch( ) ; return - 1; for( j = n; j > i; j - - ) stu[ j] = stu[ j - 1] ; stu[ j] = x;
326 C n + + ; return i;,, ;,,,,,,,, n n,, ( 3) : ;, ( ) ; : #define N 100 typedef struct stu { char name[ 20] ; float score; STU; STU stu[ N] ; int n = 0; : int deletelist( int i) { int j; if( i < 0 i > n - 1) { printf( " no this element! " ) ; getch( ) ; return - 1; for( j = i + 1; j < n; j + + ) stu[ j - 1] = stu[ j] ; 313
327 314 n - - ; return i;,,,,, n n - 1,, 9. 4, ( 1) : int insertlist ( int i, STU x) ;, : int deletelist( int i) ; : void printlist( int m) ; ( 2) : While( 1) switch( ) Case insertlist Case deletelist Case printlist Case Case Case ( 3) C : #include < stdlib. h > #include < string. h > #include < conio. h >
328 C #define N 100 typedef struct stu { char name[ 20] ; STU; float score; STU stu[ N] ; int n = 0; int insertlist( int i, STU x) ; int deletelist( int i) ; void printlist( int m) ; { char inbuf[ 10] ; int del; char chose; STU x; for( ; ; ) { clrscr( ) ; printf( " 1: Insert element to the list. \ n" ) ; printf( " 2: Delete element from the list. \n" ) ; printf( " 3: Print the list. \ n" ) ; printf( " 0: Exit. \ n" ) ; printf( " \nchose the number: " ) ; chose = getchar( ) ; getchar( ) ; switch( chose) { case 1 : gets( x. name) ; gets( inbuf) ; x. score = atof( inbuf) ; insertlist( n, x) ; break; case 2 : printf( " Input the number for delete: " ) ; scanf( " % d", &del) ; getchar( ) ; deletelist( del) ; break; case 3 : printlist( n) ; printf( " Enter any key for return menu. \ n" ) ; getch( ) ; break; 315
329 316 case 0 : exit( 1) ; default: int insertlist( int i, STU x) { int j; if( n > = N) break; { printf( " overflow! \ nprint any key for return menu. " ) ; getch( ) ; return - 1; if( i < 0 i > n) { printf( " out of range! \ nprint any key for return menu. " ) ; getch( ) ; return - 1; for( j = n; j > i; j - - ) stu[ j] = stu[ j - 1] ; stu[ j] = x; n + + ; return i; int deletelist( int i) { int j; if( i < 0 i > n - 1) { printf( " no this element! \ nprint any key for return menu. " ) ; getch( ) ; return - 1; for( j = i + 1; j < n; j + + ) n - - ; return i; stu[ j - 1] = stu[ j] ; void printlist( int m) { int i; for( i = 0 ; i < m; i + + ) printf( " % d: % s \t% f\ n", i, stu[ i]. name, stu[ i]. score) ;
330 C 2 ),,,,,,, ( NULL ) : ; : ;,,,, C : typedef struct node { elementtype data; struct node * next; NODE;, elementtype ; NODE struct node ( 1) 2 : 2 :,, NODE * create( int n) / * n * / { NODE * p, * h; int i; char inbuf[ 10] ; 317
331 318 h = ( NODE * ) malloc( sizeof( NODE) ) ; /* * / h - > next = NULL; for( i = n; i > 0; i - - ) { p = ( NODE * ) malloc( sizeof( NODE) ) ; /* * / gets( p - > name) ; gets( inbuf) ; p - > score = atof( inbuf) ; p - > next = h - > next; /* * / h - > next = p; return h;,, ( 2), void printlist( NODE * h) { NODE * current = h; while( current - > next! = NULL) { current = current - > next; printf( " % s \t% f\ n", current - > name, current - > score) ; ( 3), 9. 5, : ; ; ; void insertlist( NODE * h, char * s) { NODE * p, * old, * last;
332 C p - > next = q - > next q - > next = p 9. 5 char inbuf[ 20] ; p = ( NODE * ) malloc( sizeof( NODE) ) ; / * * / printf( " \tinput the data of the new node: \ n" ) ; gets( p - > name) ; gets( inbuf) ; p - > score = atof( inbuf) ; last = h - > next; /* * / while( strcmp( last - > name, s)! = 0&&last - > next! = NULL) { old = last; last = last - > next; if( last - > next! = NULL) /*, * / { old - > next = p; p - > next = last; Else / *, * / { last - > next = p; p - > next = NULL;,, ( name), ( 4),, 9. 6,, : ; ; 319
333 320 q - > next = p - > next free( p) ; 9. 6 void deletelist( NODE * h, char * s) { NODE * q = h, * p = h - > next; while( strcmp( p - > name, s)! = 0&&p - > next! = NULL) /* * / { q = p; p = p - > next; if( p - > next! = NULL) /* * / { q - > next = p - > next; free( p) ; else /* * / { printf( " no this element! \ n" ) ; getch( ) ;,, 9. 5, ( 1) : NODE * create( int n) ; / * n * / void insertlist( NODE * h, char * s) ; / * * / void deletelist( NODE * h, char * s) ; / * * / void printlist( NODE * h) ; / * * / ( 2) : While( 1)
334 C switch( ) Case create Case insertlist Case deletelist Case printlist Case Case Case ( 3) C : #include < stdlib. h > #include < string. h > #include < conio. h > typedef struct stu { char name[ 20] ; float score; struct stu * next; NODE; NODE * create( int n) ; void insertlist( NODE * h, char * s) ; void deletelist( NODE * h, char * s) ; void printlist( NODE * h) ; { char chose, sname[ 20] ; int n; NODE * head = NULL; for( ; ; ) { clrscr( ) ; printf( " 1: Create the list. \ n" ) ; printf( " 2: Insert element to the list. \ n" ) ; printf( " 3: Delete element from the list. \n" ) ; 321
335 322 printf( " 4: Print the list. \ n" ) ; printf( " 0: Exit. \ n" ) ; printf( " \nchose the number: " ) ; chose = getchar( ) ; getchar( ) ; switch( chose) { case 1 : Zprintf( " Input the number of List: " ) ; scanf( " % d", &n) ; getchar( ) ; head = create( n) ; break; case 2 : printf( " Input the name for INSERT: " ) ; gets( sname) ; insertlist( head, sname) ; break; case 3 : printf( " Input the data for delete: " ) ; gets( sname) ; deletelist( head, sname) ; break; case 4 : printlist( head) ; printf( " Enter any key for return menu. \ n" ) ; getch( ) ; break; case 0 : exit( 1) ; default: NODE * create( int n) { NODE * p, * h; int i; char inbuf[ 10] ; break; h = ( NODE * ) malloc( sizeof( NODE) ) ; h - > next = NULL; for( i = n; i > 0; i - - ) { p = ( NODE * ) malloc( sizeof( NODE) ) ; gets( p - > name) ; gets( inbuf) ; p - > score = atof( inbuf) ;
336 C p - > next = h - > next; h - > next = p; return h; void insertlist( NODE * h, char * s) { NODE * p, * old, * last; char inbuf[ 20] ; p = ( NODE * ) malloc( sizeof( NODE) ) ; printf( " \tinput the data of the new node: \ n" ) ; gets( p - > name) ; gets( inbuf) ; p - > score = atof( inbuf) ; last = h - > next; while( strcmp( last - > name, s)! = 0&&last - > next! = NULL) { old = last; last = last - > next; if( last - > next! = NULL) { old - > next = p; p - > next = last; else { last - > next = p; p - > next = NULL; void deletelist( NODE * h, char * s) { NODE * q = h, * p = h - > next; while( strcmp( p - > name, s)! = 0&&p - > next! = NULL) { q = p; p = p - > next; if( p - > next! = NULL) { q - > next = p - > next; free( p) ; else { printf( " no this element! \ nenter any key for return menu. \ n" ) ; 323
337 getch( ) ; void printlist( NODE * h) { NODE * current = h; while( current - > next! = NULL) { current = current - > next; printf( " % s \t% f\ n", current - > name, current - > score) ; ) 324,, ( LIFO), p, p = 0,,, : ; ( ), ; ( ), ;, ;,, 2 ) C, top, top M, top = M, top = 0,,,,,, push pop
338 C #define MAX 100 char stack[ MAX] ; int top = 0; void push( char c) / * * / { if( top > = MAX - 1) { printf( " Stack is full. \ n" ) ; exit( 1) ; else stack[ top + + ] = c; char pop( ) / * * / { char ch; if( top = = 0) { printf( " Stack is empty. \n" ) ; exit( 1 ) ; else ch = stack[ - - top] ; return ch; 9. 6 ( 1) : ;, 0; ; ; ; ( 2) C : #include < string. h > #include < stdlib. h > #define MAX 100 char stack[ MAX] ; int top = 0; void push( char c) ; char pop( ) ; 325
339 326 { char s[ 100] ; int i; printf( " Input the string s. \n" ) ; gets( s) ; for( i = 0 ; i < strlen( s) ; i + + ) /* * / push( s[ i] ) ; for( i = 0 ; i < strlen( s) ; i + + ) /* * / s[ i] = pop( ) ; s[ i] = \0 ; puts( s) ; void push( char c) /* * / { if( top > = MAX - 1) else { printf( " Stack is full. \ n" ) ; exit( 1) ; stack[ top + + ] = c; char pop( ) /* * / { char ch; if( top = = 0) { printf( " Stack is empty. \ n" ) ; else exit( 1) ; ch = stack[ - - top] ; return ch; 3 ),, stack, 9. 7, push pop 9. 7
340 C typedef struct node { char data; struct node * next; NODE; NODE * stack; void push( char c) / * * / { NODE * p; p = ( NODE* ) malloc( sizeof( NODE) ) ; p - > data = c; p - > next = stack; stack = p; char pop( ) / * * / { char ch; NODE * p; if( stack = = NULL) { printf( " Stack is empty. \ n" ) ; exit( 1) ; else { p = stack; stack = stack - > next; ch = p - > data; free( p) ; return ch; 9. 7, #include < string. h > #include < stdlib. h > typedef struct node { char data; struct node * next; NODE; NODE * stack; void push( char c) ; 327
341 328 char pop( ) ; { char s[ 100] ; int i; printf( " Input the string s. \n" ) ; gets( s) ; for( i = 0 ; i < strlen( s) ; i + + ) push( s[ i] ) ; for( i = 0 ; i < strlen( s) ; i + + ) s[ i] = pop( ) ; s[ i] = \0 ; puts( s) ; void push( char c) { NODE * p; p = ( NODE* ) malloc( sizeof( NODE) ) ; p - > data = c; p - > next = stack; stack = p; char pop( ) { char ch; NODE * p; if( stack = = NULL) { printf( " Stack is empty. \ n" ) ; else exit( 1) ; { p = stack; stack = stack - > next; ch = p - > data; free( p) ; return ch;
342 C ), ( rear), ( front) ( FIFO) : ;, ;, ; ; 2 ) ( 1), front rear, front ; rear, ( 2), front rear, 9. 9, rear, ;, 9. 9, 0 ( 3) front rear,
343 330, M : front = ( fornt + 1) % M rear = ( rear + 1) % M,, rear = front;, rear = fornt; : front ; rear ; front, ; ; : rear = front ( rear + 1 ) % M = front ( 4), : int addqueue( STU x) / * * / { if( ( rear + 1) % N = = front) { printf( " Full Queuer. \ n" ) ; else return - 1; { rear = ( rear + 1 ) % N; Que[ rear] = x; return 0; STU deletequeue( ) / * * / { STU x; if( front = = rear) { printf( " Empty Queuer. \ n" ) ; else exit( 1) ; { front = ( front + 1) % N; x = Que[ front] ; return x;
344 C 9. 8, #include < stdlib. h > #include < string. h > #include < conio. h > #define N 20 typedef struct stu { char name[ 20] ; STU; float score; STU Que[ N] ; int front = 0, rear = 0; int addqueue( STU x) ; STU deletequeue( ) ; void printqueue( ) ; { char inbuf[ 10] ; int del; char chose; STU x; for( ; ; ) { clrscr( ) ; printf( " 1: Add in queuer. \ n" ) ; printf( " 2: Delete from queuer. \n" ) ; printf( " 3: Print the queuer. \n" ) ; printf( " 0: Exit. \ n" ) ; printf( " \nchose the number: " ) ; chose = getchar( ) ; getchar( ) ; switch( chose) { case 1 : printf( " Input the element: \ n" ) ; gets( x. name) ; gets( inbuf) ; x. score = atof( inbuf) ; addqueue( x) ; break; case 2 : deletequeue( ) ; 331
345 332 break; case 3 : printqueue( ) ; printf( " Enter any key for return menu. \ n" ) ; getch( ) ; break; case 0 : exit( 1) ; default: int addqueue( STU x) break; { if( ( rear + 1) % N = = front) { printf( " Full Queuer. \ n" ) ; else return - 1; { rear = ( rear + 1 ) % N; Que[ rear] = x; return 0; STU deletequeue( ) { STU x; if( front = = rear) { printf( " Empty Queuer. \n" ) ; else exit( 1 ) ; { front = ( front + 1 ) % N; x = Que[ front] ; return x; void printqueue( ) { int i = front + 1; if( rear > = front) else for( ; i < = rear; i + + ) printf( " % d: % s\ t% f \n", i, Que[ i]. name, Que[ i]. score) ;
346 C { for( ; i < N; i + + ) printf( " % d: % s \t% f\ n", i, Que[ i]. name, Que[ i]. score) ; for( i = 0; i < = rear; i + + ) printf( " % d: % s \t% f\ n", i, Que[ i]. name, Que[ i]. score) ; 3 ),,, 9. 10,, , : front = rear ( ) ( ), 9. 11, : front = rear = ( NODE * ) malloc( sizeof( NODE) ) ; / * NODE * / rear - > next = NULL; void addqueue( NODE x) / *, x * / { NODE * p; p = ( NODE * ) malloc( sizeof( NODE) ) ; strcpy( p - > name, x. name) ; p - > score = x. score; p - > next = NULL; rear - > next = p; rear = p; void deletequeue( ) / * * / { NODE * p; if( front = = rear) { printf( " Empty Queue! \n" ) ; exit( 1) ; 333
347 334 p = front - > next; front - > next = p - > next; if( p - > next = = NULL) /*, * / rear = front; free( p) ; 9. 9,, ( ) #include < stdlib. h > #include < string. h > #include < conio. h > typedef struct stu /* * / { char name[ 20] ; float score; struct stu * next; STU; STU * front, * rear; void addqueue( STU x) ; void deletequeue( ) ; void printqueue( ) ; { char inbuf[ 10] ; int del; char chose; STU x; front = rear = ( STU* ) malloc( sizeof( STU) ) ; rear - > next = NULL; for( ; ; ) { clrscr( ) ; printf( " 1: Add in queuer. \ n" ) ; printf( " 2: Delete from queuer. \n" ) ; printf( " 3: Print the queuer. \n" ) ; printf( " 0: Exit. \ n" ) ; printf( " \nchose the number: " ) ; chose = getchar( ) ; getchar( ) ; switch( chose)
348 C { case 1 : printf( " Input the element: \ n" ) ; gets( x. name) ; gets( inbuf) ; x. score = atof( inbuf) ; addqueue( x) ; break; case 2 : deletequeue( ) ; break; case 3 : printqueue( ) ; printf( " Enter any key for return menu. \ n" ) ; getch( ) ; break; case 0 : exit( 1) ; default: void addqueue( STU x) { STU * p; break; p = ( STU * ) malloc( sizeof( STU) ) ; strcpy( p - > name, x. name) ; p - > score = x. score; p - > next = NULL; rear - > next = p; rear = p; void deletequeue( ) { STU * p; if( front = = rear) { printf( " Empty Queue! \n" ) ; exit( 1) ; p = front - > next; front - > next = p - > next; if( p - > next = = NULL) free( p) ; rear = front; void printqueue( ) 335
349 { STU * p = front - > next; while( p! = NULL) { printf( " % s \t% f\ n", p - > name, p - > score) ; p = p - > next; ( C ),, N N - 1, ( ),,,, ( ),, ( ), ( ) : n, ( ), 1 ; N - 1 ( ), 2 ;, ( ), : ( ), ; ; ( ), ;, 9. 12,
350 C : [ ] 1 : 1 [ ] 2 : 1 3 [ ] 3 : [ ] 4 : [ ] 5 : [ ] 6 : [ 24 ] : typedef struct word { char w[ 20] ; / *, * / int count; WORD; void selectsort( WORD v[ ], int n) { int i, j, k; WORD t; for( i = 0 ; i < n - 1; i + + ) * / { k = i; for( j = i + 1; j < n; j + + ) if( v [ j]. count > v[ k]. count) if( k! = i) k = j; t = v[ i], v[ i] = v[ k], v[ k] = t; / * n, n - 1 n, n - 1, 1 n - 1, 2 n - 2, i n - i, n - 1 1, : n - 1 ( n - i) = 1 i = 1 2 ( n2 - n) 337 O( n 2 ) 9. 10, #include < stdlib. h > #define N 10 / * * / typedef struct word / * * / { char w[ 20] ; int count; WORD;
351 338 void selectsort( WORD v[ ], int n) ; { WORD a[ N] ; char inbuf[ 20] ; int i; for( i = 0 ; i < N; i + + ) / * * / { gets( a[ i]. w) ; gets( inbuf) ; a[ i]. count = atoi( inbuf) ; selectsort( a, N) ; for( i = 0 ; i < N; i + + ) printf( " % d \ t% s \ n", a[ i]. count, a[ i]. w) ; void selectsort( WORD v[ ], int n) { int i, j, k; WORD t; for( i = 0 ; i < n - 1 ; i + + ) { k = i; for( j = i + 1; j < n; j + + ) if( v [ j]. count > v[ k]. count) k = j; if( k! = i) t = v[ i], v[ i] = v[ k], v[ k] = t; ,,,,, :, ;, ;,
352 C ; ;,, 9. 13, : [ 6 ] : [ 5 6 ] : [ ] : [ ] : [ ] : [ ] 1 6 : [ ] : #define N 10 typedef struct word { char w[ 20] ; int count; WORD; void insertsort( WORD v[ ], int n) { int i, j; for( i = 2 ; i < = n; i + + ) { v[ 0] = v[ i] ; /* 0 * / for( j = i - 1; v[ 0 ]. count > v[ j]. count; j - - ) / * v[ j + 1] = v[ j] ; * / v[ j + 1 ] = v[ 0] ; / * * /,, ( 0 ),,, n n - 1, 1 2, 2 3, i i + 1, n n + 1 : n i = 1 i = 2 2 ( n + 2 ) ( n - 1) O( n 2 ) 9. 11, 339
353 340 #include < stdlib. h > #define N 10 typedef struct word { char w[ 20] ; int count; WORD; void insertsort( WORD v[ ], int n) ; { WORD a[ N + 1] ; / * * / char inbuf[ 20] ; int i; for( i = 1 ; i < N + 1; i + + ) /* 0, * / { gets( a[ i]. w) ; gets( inbuf) ; a[ i]. count = atoi( inbuf) ; insertsort( a, N) ; for( i = 1 ; i < N + 1; i + + ) printf( " % d \ t% s \ n", a[ i]. count, a[ i]. w) ; void insertsort( WORD v[ ], int n) { int i, j; for( i = 2 ; i < = n; i + + ) { v[ 0] = v[ i] ; for( j = i - 1; v[ 0 ]. count > v[ j]. count; j - - ) v[ j + 1] = v[ j] ; v[ j + 1 ] = v[ 0] ; ,,, : While( ) ;
354 C If( ), ; Else, ; : #define N 10 typedef struct word { char w[ 20] ; int count; WORD; void binsertsort( WORD v[ ], int n) { int i, j, low, high, mid; for( i = 2 ; i < = n; i + + ) { v[ 0] = v[ i] ; / * * / low = 1, high = i - 1; / * low, high * / while( low < = high) / * * / { mid = ( low + high) /2; if( v [ 0]. count > v[ mid]. count) high = mid - 1; else low = mid + 1 ; for( j = i - 1; j > = low; j - - ) / * * / v[ j + 1] = v[ j] ; v[ low] = v[ 0] ; / * * /, O( nlog 2 n),, O( n 2 ), O( n 2 ) 9. 12, #include < stdlib. h > #define N 10 typedef struct word { char w[ 20] ; int count; 341
355 342 WORD; void binsertsort( WORD v[ ], int n) ; { WORD a[ N + 1] ; char inbuf[ 20] ; int i; for( i = 1 ; i < N + 1; i + + ) { gets( a[ i]. w) ; gets( inbuf) ; a[ i]. count = atoi( inbuf) ; binsertsort( a, N) ; for( i = 1 ; i < N + 1; i + + ) printf( " % d \ t% s \ n", a[ i]. count, a[ i]. w) ; void binsertsort( WORD v[ ], int n) { int i, j, low, high, mid; for( i = 2 ; i < = n; i + + ) { v[ 0] = v[ i] ; low = 1, high = i - 1; while( low < = high) { mid = ( low + high) /2 ; if( v [ 0]. count > v[ mid]. count) high = mid - 1; else low = mid + 1 ; for( j = i - 1; j > = low; j - - ) v[ j + 1] = v[ j] ; v[ low] = v[ 0] ; ,, :
356 C,,,, ( ) ;, ;, n n - 1 : #define N 10 typedef struct word { char w[ 20] ; int count; WORD; void bubblesort( WORD v[ ], int n) { int i, j, flag = 1; / * flag 1* / i = n - 1; / * n - 1 * / while( i > 0&&! flag) / * * / { flag = 0; / * flag = 0* / for( j = 1 ; j < = i; j + + ) if( v[ j + 1]. count > v[ j]. count) { flag = 1 ; / *, flag i - - ; = 1* / v[ 0] = v[ j], v[ j] = v[ j + 1], v[ j + 1] = v[ 0] ;,,, flag( 1 ), flag 0 ( ),, 0, ; 1, : :, n n - 1, 2 ( i - 1) i = n = 1 2 ( n 2 - n), 3, 2 3 ( i - 1) = 3 i = n 2 ( n 2 - n) O( n 2 ) 9. 13, 343
357 344 #include < stdlib. h > #define N 10 typedef struct word { char w[ 20] ; int count; WORD; void bubblesort( WORD v[ ], int n) ; { WORD a[ N + 1] ; char inbuf[ 20] ; int i; for( i = 1 ; i < N + 1; i + + ) { gets( a[ i]. w) ; gets( inbuf) ; a[ i]. count = atoi( inbuf) ; bubblesort( a, N) ; for( i = 1 ; i < N + 1; i + + ) printf( " % d \ t% s \ n", a[ i]. count, a[ i]. w) ; void bubblesort( WORD v[ ], int n) { int i, j, flag = 1; i = n - 1; while( i > 0&&! flag) { flag = 0; for( j = 1 ; j < = i; j + + ) if( v[ j + 1]. count > v[ j]. count) { flag = 1 ; v[ 0] = v[ j], v[ j] = v[ j + 1], v[ j + 1] = v[ 0] ; i - - ; ( D. L. Shell) 1959,
358 C :,,,, 1,, : ( ) ;, ; ( ) ;, 1, ( 38, 26, 54, 87, 65, 16, 3, 26 ), : : : : : #define N 10 typedef struct word { char w[ 20] ; int count; WORD; void shellsort( WORD v[ ], int n) { int i, j, gap; WORD temp; for( gap = n /2; gap > 0; gap / = 2) /*, * / for( i = gap; i < n; i + + ) /* * / for( j = i - gap; j > = 0&&v[ j]. count < v[ j + gap]. count; j - = gap) temp = v[ j], v[ j] = v[ j + gap], v[ j + gap] = temp; 9. 14, #include < stdlib. h > #define N 10 typedef struct word { char w[ 20] ; int count; 345
359 346 WORD; void shellsort( WORD v[ ], int n) ; { WORD a[ N] ; char inbuf[ 20] ; int i; for( i = 0 ; i < N; i + + ) { gets( a[ i]. w) ; gets( inbuf) ; a[ i]. count = atoi( inbuf) ; shellsort( a, N) ; for( i = 0 ; i < N; i + + ) printf( " % d \ t% s \ n", a[ i]. count, a[ i]. w) ; void shellsort( WORD v[ ], int n) { int i, j, gap; WORD temp; for( gap = n /2; gap > 0; gap / = 2) for( i = gap; i < n; i + + ) for( j = i - gap; j > = 0&&v[ j]. count < v[ j + gap]. count; j - = gap) temp = v[ j], v[ j] = v[ j + gap], v[ j + gap] = temp; , :,,,,, ;,, ( 45, 21, 53, 13, 86, 79, 67, 36 ) 9. 15,,
360 C : : [ ] 13 2 : [ ] 45 [ 36 21] 13 3 : [ ] [ 36 21] 13 4 : [ 86 79] [ 36 21] 13 5 : [ 36 21] 13 6 : : typedef struct word { char w[ 20] ; int count; WORD; void quicksort( WORD v[ ], int left, int right) { void swap( WORD v[ ], int i, int j) ; int i, last; WORD t; if( left > = right) / * 1 * / return; swap( v, left, ( left + right) /2) ; / * * / last = left; for( i = left + 1; i < = right; i + + ) if( v [ i]. count > v[ left]. count) swap( v, + + last, i) ; swap( v, left, last) ; quicksort( v, left, last - 1) ; / * * / quicksort( v, last + 1, right) ; / * * / void swap( WORD v[ ], int i, int j) / * * / { WORD t; t = v[ i], v[ i] = v[ j], v[ j] = t; 9. 15, #include < stdlib. h > #define N 8 typedef struct word { char w[ 20] ; 347
361 348 int count; WORD; void quicksort( WORD v[ ], int left, int right) ; { WORD a[ N] ; char inbuf[ 20] ; int i; for( i = 0 ; i < N; i + + ) { gets( a[ i]. w) ; gets( inbuf) ; a[ i]. count = atoi( inbuf) ; quicksort( a, 0, N - 1) ; for( i = 0 ; i < N; i + + ) printf( " % d \ t% s \ n", a[ i]. count, a[ i]. w) ; void quicksort( WORD v[ ], int left, int right) { void swap( WORD v[ ], int i, int j) ; int i, last; WORD t; if( left > = right) return; swap( v, left, ( left + right) /2) ; last = left; for( i = left + 1 ; i < = right; i + + ) if( v[ i]. count > v[ left]. count) swap( v, + + last, i) ; swap( v, left, last) ; quicksort( v, left, last - 1 ) ; quicksort( v, last + 1, right) ; void swap( WORD v[ ], int i, int j) { WORD t; t = v[ i], v[ i] = v[ j], v[ j] = t; 9. 3,
362 C :,,,, 3 : ; ;, n, ( ASL: Average Search Length) : n ASL = P i C i i = 1 : P i i, C i i ASL, ASL,,, , :,,,, : #define N 10 typedef struct word { char w[ 20] ; int count; WORD; int listsearch( WORD v[ ], int key, int n) { int i; v[ 0]. count = key; / * * / for( i = n; v[ i]. count! = key; i - - ) ; return i; / * 0, 0* /, 0
363 350,, :, n P = 1 /n,, i C i, : n ASL = P i C i i = 1 = 1 n n i = 1 i = 1 2 ( n + 1), ( ) #include < stdlib. h > #define N 10 typedef struct word { char w[ 20] ; int count; WORD; int listsearch( WORD v[ ], int key, int n) ; { WORD a[ N + 1] ; char inbuf[ 20] ; int i, key, result; for( i = 1 ; i < N + 1; i + + ) { gets( a[ i]. w) ; gets( inbuf) ; a[ i]. count = atoi( inbuf) ; printf( " Input the key: " ) ; scanf( " % d", &key) ; if( ( result = listsearch( a, key, N) ) > 0 ) else printf( " a[ % d] : % d \ t% s \n", result, a[ result]. count, a[ result]. w) ; printf( " No this element. \n" ) ; int listsearch( WORD v[ ], int key, int n) { int i; v[ 0]. count = key; return i; for( i = n; v[ i]. count! = key; i - - ) ;
364 C ,, : :, 2,,,,, : #define N 10 typedef struct word { char w[ 20] ; int count; WORD; int binarysearch( WORD v[ ], int key, int n) { int low = 0, high = n - 1, mid; while( low < = high) / * * / { mid = ( low + high) /2; / * * / if( key > v[ mid]. count) low = mid + 1; / *, * / else if( key < v[ mid]. count) high = mid - 1; / *, * / else return mid; / *, * / return - 1; / *, - 1* / :,, : 351
365 ASL = n + 1 log 2 ( n + 1) - 1 log 2 n n, 1 ( ) #include < stdlib. h > #define N 10 typedef struct word { char w[ 20] ; int count; WORD; int binarysearch( WORD v[ ], int key, int n) ; { WORD a[ N] ; char inbuf[ 20] ; int i, key, result; for( i = 0 ; i < N; i + + ) { gets( a[ i]. w) ; gets( inbuf) ; a[ i]. count = atoi( inbuf) ; printf( " Input the key: " ) ; scanf( " % d", &key) ; if( ( result = binarysearch( a, key, N) ) > 0 ) else printf( " a[ % d] : % d \ t% s \n", result, a[ result]. count, a[ result]. w) ; printf( " No this element. \n" ) ; int binarysearch( WORD v[ ], int key, int n) { int low = 0, high = n - 1, mid; while( low < = high) { mid = ( low + high) /2; if( key > v[ mid]. count) low = mid + 1; else if( key < v[ mid]. count) else high = mid - 1; return mid;
366 C return - 1; C, 2,, ; ( Shanding),,, ( ),, ; +,,, CAD,,,,,, 25 80,,, 9. 16, = ,, 9. 16,, X, Y 0, , C ( Turbo C ), graphics. h, 2 : 353
367 Options /Linker Graphics lib on; * BGI; C 1 ) 354,,,, ( ),, : void far initgraph( int far * gdriver, int far * gmode, char * path) ; gdriver gmode, path,. BGI, EGA VGA EGAVGA. BGI 9. 1, path, ( path ),, 2 :, : void far detectgraph( int * gdriver, * gmode) ; initgraph detectgraph gdriver gmode initgraph initgraph gdriver 9. 1 DETECT #include < graphics. h > #include < conio. h > { int gdriver = DETECT, gmode, maxx, maxy; initgraph( &gdriver, &gmode, " d: \ \ thec \ \ tc \ \ bgi" ) ; / * maxx = getmaxx( ) ; * / / * getmaxx X * /
368 C maxy = getmaxy( ) ; / * getmaxy Y * / printf( " resolving power = % d % d \ n", maxx, maxy) ; getch( ) ; closegraph( ) ; 9. 1 ( gdriver) ( gmode) CGA 1 CGAC0 0 C0 320* 200 CGAC1 1 C1 320* 200 CGAC2 2 C2 320* 200 CGAC3 3 C3 320* 200 CGAHI * 200 MCGA 2 MCGAC0 0 C0 320* 200 MCGAC1 1 C1 320* 200 MCGAC2 2 C2 320* 200 MCGAC3 3 C3 320* 200 MCGAMED * 200 MCGAHI * 480 EGA 3 EGALO * 200 EGAHI * 350 EGA64 4 EGA64LO * 200 EGA64HI * 350 EGAMON 5 EGAMONHI * 350 IBM IBM8514LO * 480 IBM8514HI * 768 HERC 7 HERCMONOHI * 348 ATT400 8 ATT400C0 0 C0 320* 200 ATT400C1 1 C1 320* 200 ATT400C2 2 C2 320* 200 ATT400C3 3 C3 320* 200 ATT400MED * 200 ATT400HI * 200 VGA 9 VGALO * 200 VGAMED * 350 VGAHI * 480 PC PC3270HI * 350 DETECT : initgraph( &gdriver, &gmode, " d: \ \ thec \ \ tc \ \ bgi" ) ;
369 356 : initgraph( &gdriver, &gmode, " " ) ;,, C GRAPHICS. LIB, ( EGAVGA. BGI ) : BGIOBJ ( EGAVGA. OBJ), C BGIOBJ EGAVGA TLIB ( EGAVGA. OBJ) LIB GRAPHICS. LIB, TLIB LIB\ GRAPHICS. LIB + EGAVGA, registerbgidriver( EGAVGA_driver) ; / *, * / #include < graphics. h > #include < conio. h > { int gdriver = DETECT, gmode, maxx, maxy; registerbgidriver( EGAVGA_driver) ; /* * / initgraph( &gdriver, &gmode, " " ) ; maxx = getmaxx( ) ; maxy = getmaxy( ) ; printf( " resolving power = % dx% d \ n", maxx, maxy) ; getch( ) ; closegraph( ) ; 2 ), : void far setbkcolor( int color) ; void far setcolor( int color) ; ( ) int far getbkcolor( void) ; ( )
370 C int far getcolor( void) ; int far getmaxcolor( void) ; voide far cleardevice( void) ; ( ) ( ) color, EGA VGA, EGA VAG BLACK 0 DARKGRAY 8 BLUE 1 LIGHTBLUE 9 GREEN 2 LIGHTGREEN 10 CYAN 3 LIGHTCYAN 11 RED 4 LIGHTRED 12 MAGENTA 5 LIGHTMAGENTA 13 BROWN 6 YELLOW 14 LIGHTGRAY 7 WHITE ) : int far getmaxx( void) ; x int far getmaxy( void) ; y int far getx( void) ; x void far gety( void) ; y void far moveto( int x, int y) ; ( x, y) void far moverel( int dx, int dy) ; ( x, y) ( x + dx, y + dy) void far putpixel( int x, int y, int color) ; color color 9. 2, x, y int far getpixel( int x, int y) ; ( x, y) 4 ), : void far line( int x0, int y0, int x1, int y1) ; ( x0, y0 ) ( x1, y1) void far lineto( int x, int y) ; ( x, y) void far linerel( int dx, int dy) ; ( x, y)
371 358 dx dy ( x + dx, y + dy) void far circle( int x, int y, int radius) ; ( x, y), radius, void far arc( int x, int y, int stangle, int endangle, int radius) ; ( x, y), radius, stangle endangle ( ) TURBO x 0,, 90, 180, , void ellipse( int x, int y, int stangle, int endangle, int xradius, int yradius) ; ( x, y), xradius, yradius x y, stangle endangle, stangle = 0, endangle = 360, void far rectangle( int x1, int y1, int x2, inty2 ) ; ( x1, y1), ( x2, y2) void far drawpoly( int numpoints, int far * polypoints) ; numpoints, polypoints polypoints 2 x, y, x, numpoints, polypoints void far setlinestyle ( int? linestyle, unsigned? upattern, int thickness) ;, linestyle, 9. 3, thickness, 9. 4 upattern, linestyle USERBIT_LINE ( upattern 0 ), uppattern 16, 1, ( ), ( ) 9. 3 SOLID_LINE 0 DOTTED_LINE 1 CENTER_LINE 2 DASHED_LINE 3 USERBIT_LINE NORM_WIDTH 1 THIC_WIDTH 3 void far getlinesettings( struct linesettingstype far * lineinfo) ;
372 C lineinfo, linesettingstype : struct linesettingstype { int linestyle; unsigned upattern; int thickness; 1 void far setwritemode( int mode) ; mode = 0, ; mode = 1, ( XOR), #include < conio. h > #include < graphics. h > { int gdriver = DETECT, gmode, i; registerbgidriver( EGAVGA_driver) ; initgraph( &gdriver, &gmode, " d: \ \ thec \ \ tc" ) ; setbkcolor( BLUE) ; cleardevice( ) ; setcolor( GREE N) ; circle( 320, 240, 98) ; setlinestyle( 0, 0, 3) ; setcolor( 2) ; rectangle( 220, 140, 420, 340) ; setcolor( WHITE) ; setlinestyle( 4, 0xaaaa, 1) ; getch( ) ; closegraph( ) ; ),,, : void far bar( int x1, int y1, int x2, int y2) ; ( x1, y1), ( x2, y2),, void far bar3d( int x1, int y1, int x2, int y2, int? depth, int topflag) ;
373 topflag 0, topflag 0, ( ) bar3d( ), 45, void far pieslice( int x, int y, int stangle, int? endangle, int radius) ; ( x, y), radius, stangle, endangle, stangle = 0, endangle = 360, X void far sector( int x, int y, int stanle, int endangle, intxradius, int yradius) ; ( x, y), xradius, yradius x y, stangle, endangle,, : void far setfillstyle( int pattern, int color) ;, color pattern pattern 360 EMPTY_FILL 0 SOLID_FILL 1 LINE_FILL 2 LTSLASH_FILL 3 ( ) SLASH_FILL 4 ( ) BKSLASH_FILL 5 ( ) LTBKSLASH_FILL 6 ( ) HATCH_FILL 7 XHATCH_FILL 8 INTTERLEAVE_FILL 9 WIDE_DOT_FILL 10 CLOSE_DOS_FILL 11 USER_FILL 12 void far setfillpattern( char * upattern, int color) ; upattern , 8 8, #include < graphics. h >
374 C #include < dos. h > #include < conio. h > { int gdriver = DETECT, gmode, i; registerbgidriver( EGAVGA_driver) ; initgraph( &gdriver, &gmode, " d: \ \ thec \ \ tc" ) ; setbkcolor( BLUE) ; cleardevice( ) ; for( i = 0 ; i < 13; i + + ) { setcolor( i + 3) ; setfillstyle( i, 2 + i) ; / * * / bar( 100, 150, 200, 50 ) ; bar3 d( 300, 100, 500, 200, 70, 1) ; pieslice( 200, 300, 90, 180, 90 ) ; sector( 500, 300, 180, 270, 200, 100) ; delay( 2000) ; / * 2 * / getch( ) ; closegraph( ) ; ), ( 0, 0 ),,,,,,,, setviewport( ) : void far setviewport( int xl, int yl, int x2, int y2, int clipflag) ; ( xl, yl), ( x2, y2), x1, y1, x2, y2 clipflag 0,, clipflag 0, void far clearviewport( void) ; void far getviewsettings( struct viewporttype far * viewport) ;, viewporttype viewport, viewporttype : struct viewporttype
375 { int left; int top; int right; int bottom; int cliplag; ; 7 ) 362,, printf( ), puts( ), putchar ( ),, 80, 25,, : void far outtext( char far * textstring) ; textstring void far outtextxy( int x, int y, char far * textstring) ; textstring ( x, y) x y int sprintf( char * str, char * format, variable_list) ;, printf( ) str, void far settexjustify( int horiz, int vert) ; outtextxy( int x, int y, char far * str textstring), ( x, y) :,,, 3,,, 3, 9 settextjustify( ) horiz 3, 2 vert 3,, outtextxy( ), ( x, y) outtext( ), horiz vert horiz vert LEFT_TEXT 0 RIGHT_TEXT 2 BOTTOM_TEXT 0 TOP_TEXT 2 CENTER_TEXT 1
376 C void far settextstyle( int font, int direction, int charsize) ; ( font ) ( direction ) ( charsize ) font 9. 7, direction 9. 8, charsize font( ) DEFAULT_FONT ( ) TRIPLEX_FONT 1 3 SMALL_FONT 2 SANSSERIF_FONT 3 GOTHIC_FONT direction( ) HORIZ_DIR 0 VERT_DIR charsize( ) / USER_CHAR_SIZE = 0 void far setusercharsize( int mulx, int divx, int muly, int divy) ;, settextstyle ( ) charsize 0 ( USER _ CHAR_SIZE), settextstyle ( ) setusercharsize( ),? : x( mulx/ divx),
377 364 : y( muly / divy) #include < graphics. h > #include < conio. h > { int gdriver = DETECT, gmode; registerbgidriver( EGAVGA_driver) ; initgraph( &gdriver, &gmode, " d: = \ \ thec \ \ tc" ) ; setbkcolor( BLUE) ; cleardevice( ) ; setfillstyle( 1, 2 ) ; setcolor( WHITE) ; rectangle( 100, 100, 330, 380) ; floodfill( 50, 50, 14) ; setcolor( RED) ; settextstyle( 1, 1, 8) ; outtextxy( 210, 120, " Chongqing University" ) ; setusercharsize( 2, 1, 4, 1) ; setcolor( 15) ; settextstyle( 3, 0, 5) ; outtextxy( 220, 220, " Chongqing University" ) ; setusercharsize( 4, 1, 1, 1) ; settextstyle( 3, 0, 0) ; outtextxy( 220, 120, " GOOD" ) ; getch( ) ; closegraph( ) ; C,,, 1 ),, :
378 C X = xcos - ysin Y = xsini + ycos, ( X, Y), ( x, y), 4, ( x, y), void rotate_point( double theta, double * x, double * y, int x_org, int y_org) { double tx, ty; tx = * x - x_org; ty = * y - y_org; * x = tx* cos( theta) - ty* sin( theta) ; * y = tx* sin( theta) + ty* cos( theta) ; * x + = x_org; * y + = y_org; ( x, y), : ) ;, ;, (, 3 for( j = 0; j < 4; j + + ) { c = getcolor( ) ; / * * / setcolor( getbkcolor( ) ) ; /* * / line( ( int) ob[ j] [ 0], ( int) ob[ j] [ 1 ], ( int) ob[ j] [ 2], ( int) ob[ j] [ 3] ) ; / *, * / rotate_point( theta, &ob[ j] [ 0], &ob[ j] [ 1 ], x, y) ; / * / rotate_point( theta, &ob[ j] [ 2], &ob[ j] [ 3 ], x, y) ; setcolor( c) ; / * * / line( ( int) ob[ j] [ 0], ( int) ob[ j] [ 1 ], ( int) ob[ j] [ 2], ( int) ob[ j] [ 3] ) ; / * * /,, R, L, #include < graphics. h > #include < conio. h > #include < ctype. h > 365
379 366 #include < math. h > { void rotate_obj( double ob[ ] [ 4 ], double theta, int x, int y, int sides) ; void display_obj( double ob[ ] [ 4], int sides) ; double obj[ 4] [ 4] = {100, 100, 100, 150, 100, 150, 120, 150, 120, int gdriver = DETECT, gmode, maxx, maxy; registerbgidriver( EGAVGA_driver) ; 150, 120, 100, 120, 100, 100, 100 ; / * * / initgraph( &gdriver, &gmode, " d: \ \ thec \ \ tc" ) ; display_obj( obj, 4) ; rotate_obj( obj, 1. 55, 125, 110, 4) ; void display_obj( double ob[ ] [ 4 ], int sides) / * * / { int i; for( i = 0 ; i < sides; i + + ) line( ( int) ob[ i] [ 0], ( int) ob[ i] [ 1], ( int) ob[ i] [ 2], ( int) ob[ i] [ 3] ) ; void rotate_obj( double ob[ ] [ 4 ], double theta, int x, int y, int sides) { void rotate_point( double theta, double * x, double * y, int x_org, int y_org) ; int i, j; char ch; for( ; ; ) { ch = getch( ) ; switch( tolower( ch) ) { case l : theta = theta < 0? - theta: theta; break; case r : theta = theta > 0? - theta: theta; default: break; return; for( j = 0; j < sides; j + + ) { int c = getcolor( ) ; setcolor( getbkcolor( ) ) ; line( ( int) ob[ j] [ 0], ( int) ob[ j] [ 1], ( int) ob[ j] [ 2], ( int) ob[ j] [ 3] ) ; rotate_point( theta, &ob[ j] [ 0 ], &ob[ j] [ 1], x, y) ; rotate_point( theta, &ob[ j] [ 2 ], &ob[ j] [ 3], x, y) ; setcolor( c) ; line( ( int) ob[ j] [ 0], ( int) ob[ j] [ 1], ( int) ob[ j] [ 2], ( int) ob[ j]
380 C [ 3] ) ; void rotate_point( double theta, double * x, double * y, int x_org, int y_org) { double tx, ty; tx = * x - x_org; ty = * y - y_org; * x = tx* cos( theta) - ty* sin( theta) ; * y = tx* sin( theta) + ty* cos( theta) ; * x + = x_org; * y + = y_org; 2 ),, ( startx, starty), ( endx, endy) ( x, y) : void copy( int startx, int starty, int endx, int endy, int x, int y) { int i, j, c; for( i = startx; i < = endx; i + + ) for( j = starty; j < = endy; j + + ) { c = getpixel( i, j) ; putpixel( x + i, y + j, c) ;, ( startx, starty), ( endx, endy) ( x, y) : void move( int startx, int starty, int endx, int endy, int x, int y) { int i, j, c; for( i = startx; i < = endx; i + + ) for( j = starty; j < = endy; j + + ) { c = getpixel( i, j) ; putpixel( x + i, y + j, c) ; putpixel( i, j, c^c) ; 367
381 #include < graphics. h > #include < conio. h > #include < ctype. h > #include < math. h > { void display_obj( double ob[ ] [ 4], int sides) ; void copy( int startx, int starty, int endx, int endy, int x, int y) ; void move( int startx, int starty, int endx, int endy, int x, int y) ; double obj[ 4] [ 4] = {100, 100, 100, 150, 100, 150, 120, 150, 120, 150, 120, 100, 120, 100, 100, 100 ; int gdriver = DETECT, gmode, maxx, maxy; registerbgidriver( EGAVGA_driver) ; initgraph( &gdriver, &gmode, " d: \ \ thec \ \ tc" ) ; display_obj( obj, 4) ; copy( 95, 95, 125, 155, 300, 150 ) ; getch( ) ; move( 95, 95, 125, 155, 160, 300) ; getch( ) ; void display_obj( double ob[ ] [ 4 ], int sides) { int i; for( i = 0 ; i < sides; i + + ) line( ( int) ob[ i] [ 0], ( int) ob[ i] [ 1], ( int) ob[ i] [ 2], ( int) ob[ i] [ 3] ) ; void copy( int startx, int starty, int endx, int endy, int x, int y) { int i, j, c; for( i = startx; i < = endx; i + + ) for( j = starty; j < = endy; j + + ) { c = getpixel( i, j) ; putpixel( x + i, y + j, c) ; void move( int startx, int starty, int endx, int endy, int x, int y) { int i, j, c; for( i = startx; i < = endx; i + + ) for( j = starty; j < = endy; j + + )
382 C { c = getpixel( i, j) ; putpixel( x + i, y + j, c) ; putpixel( i, j, c^c) ; : :,,, 9. 2 ( 0 ), :,, 9. 3 : n( n > 0), 1, 2,, n, start ( start > 0), 1 end( end > 0), end ;, end ; : ( 1) n n ( 2) ( 3),, newh, newh ( 4) newh : ( 1), ; ( 2) : typedef struct node { float coef; / * * / int exp; / * * / struct node * next; / * * / NODE; 369
383 370 [ 1] Brian W. Kernighan, Dennis M. Rithie, The C Proramming Language, Second Edition. Pretice - Hall International, Inc. :, 1997 [ 2],,.. :, 2000 [ 3].. :, 1989 [ 4],,. C. :, 1999 [ 5] Al Kelley, Ira Pohl, A Book on c: Programming in C( C ). :, 2004 [ 6] H. M. Deitel, P. J. Deitel.. C. :, 2000 [ 7] Samuel P. Harbison III, Guy L. Steele Jr., A Reference Manual( C ) 5th. :, 2003 [ 8] Matthias Felleisen,,. How To Design Programs( ). :, 2003 [ 9], C ( 3 ),, 1995 [ 10] Robert Sedgewick.. C ( : ) 3th. :, 2004 [ 11],. C. :, 2003 [ 12],,,,,. :, 2004 [ 13],. ( C ). :, 1999
新版 明解C言語入門編
328, 4, 110, 189, 103, 11... 318. 274 6 ; 10 ; 5? 48 & & 228! 61!= 42 ^= 66 _ 82 /= 66 /* 3 / 19 ~ 164 OR 53 OR 164 = 66 ( ) 115 ( ) 31 ^ OR 164 [] 89, 241 [] 324 + + 4, 19, 241 + + 22 ++ 67 ++ 73 += 66
CC213
: (Ken-Yi Lee), E-mail: [email protected] 49 [P.51] C/C++ [P.52] [P.53] [P.55] (int) [P.57] (float/double) [P.58] printf scanf [P.59] [P.61] ( / ) [P.62] (char) [P.65] : +-*/% [P.67] : = [P.68] : ,
FY.DOC
高 职 高 专 21 世 纪 规 划 教 材 C++ 程 序 设 计 邓 振 杰 主 编 贾 振 华 孟 庆 敏 副 主 编 人 民 邮 电 出 版 社 内 容 提 要 本 书 系 统 地 介 绍 C++ 语 言 的 基 本 概 念 基 本 语 法 和 编 程 方 法, 深 入 浅 出 地 讲 述 C++ 语 言 面 向 对 象 的 重 要 特 征 : 类 和 对 象 抽 象 封 装 继 承 等 主
Ps22Pdf
C ( CIP) C /. :, 2001. 7 21 ISBN 7-5624 -2355-5. C........ C. TP312 CIP ( 2001 ) 034496 C * * : 7871092 1 /16 : 14. 25 : 356 20017 1 20017 1 : 1 6 000 ISBN 7-5624-2355-5 / TP311 : 21. 00 C, C,,,, C,, (
C/C++ - 文件IO
C/C++ IO Table of contents 1. 2. 3. 4. 1 C ASCII ASCII ASCII 2 10000 00100111 00010000 31H, 30H, 30H, 30H, 30H 1, 0, 0, 0, 0 ASCII 3 4 5 UNIX ANSI C 5 FILE FILE 6 stdio.h typedef struct { int level ;
新・解きながら学ぶC言語
330!... 67!=... 42 "... 215 " "... 6, 77, 222 #define... 114, 194 #include... 145 %... 21 %... 21 %%... 21 %f... 26 %ld... 162 %lf... 26 %lu... 162 %o... 180 %p... 248 %s... 223, 224 %u... 162 %x... 180
nooog
C : : : , C C,,, C, C,, C ( ), ( ) C,,, ;,, ; C,,, ;, ;, ;, ;,,,, ;,,, ; : 1 9, 2 3, 4, 5, 6 10 11, 7 8, 12 13,,,,, 2008 1 1 (1 ) 1.1 (1 ) 1.1.1 ( ) 1.1.2 ( ) 1.1.3 ( ) 1.1.4 ( ) 1.1.5 ( ) 1.2 ( ) 1.2.1
新・明解C言語入門編『索引』
!... 75!=... 48 "... 234 " "... 9, 84, 240 #define... 118, 213 #include... 148 %... 23 %... 23, 24 %%... 23 %d... 4 %f... 29 %ld... 177 %lf... 31 %lu... 177 %o... 196 %p... 262 %s... 242, 244 %u... 177
_汪_文前新ok[3.1].doc
普 通 高 校 本 科 计 算 机 专 业 特 色 教 材 精 选 四 川 大 学 计 算 机 学 院 国 家 示 范 性 软 件 学 院 精 品 课 程 基 金 青 年 基 金 资 助 项 目 C 语 言 程 序 设 计 (C99 版 ) 陈 良 银 游 洪 跃 李 旭 伟 主 编 李 志 蜀 唐 宁 九 李 涛 主 审 清 华 大 学 出 版 社 北 京 i 内 容 简 介 本 教 材 面 向
C/C++程序设计 - 字符串与格式化输入/输出
C/C++ / Table of contents 1. 2. 3. 4. 1 i # include # include // density of human body : 1. 04 e3 kg / m ^3 # define DENSITY 1. 04 e3 int main ( void ) { float weight, volume ; int
C/C++语言 - C/C++数据
C/C++ C/C++ Table of contents 1. 2. 3. 4. char 5. 1 C = 5 (F 32). 9 F C 2 1 // fal2cel. c: Convert Fah temperature to Cel temperature 2 # include < stdio.h> 3 int main ( void ) 4 { 5 float fah, cel ;
C/C++ 语言 - 循环
C/C++ Table of contents 7. 1. 2. while 3. 4. 5. for 6. 8. (do while) 9. 10. (nested loop) 11. 12. 13. 1 // summing.c: # include int main ( void ) { long num ; long sum = 0L; int status ; printf
C 1
C homepage: xpzhangme 2018 5 30 C 1 C min(x, y) double C // min c # include # include double min ( double x, double y); int main ( int argc, char * argv []) { double x, y; if( argc!=
C/C++ - 字符输入输出和字符确认
C/C++ Table of contents 1. 2. getchar() putchar() 3. (Buffer) 4. 5. 6. 7. 8. 1 2 3 1 // pseudo code 2 read a character 3 while there is more input 4 increment character count 5 if a line has been read,
C C
C C 2017 3 8 1. 2. 3. 4. char 5. 2/101 C 1. 3/101 C C = 5 (F 32). 9 F C 4/101 C 1 // fal2cel.c: Convert Fah temperature to Cel temperature 2 #include 3 int main(void) 4 { 5 float fah, cel; 6 printf("please
新版 明解C++入門編
511!... 43, 85!=... 42 "... 118 " "... 337 " "... 8, 290 #... 71 #... 413 #define... 128, 236, 413 #endif... 412 #ifndef... 412 #if... 412 #include... 6, 337 #undef... 413 %... 23, 27 %=... 97 &... 243,
C/C++语言 - 运算符、表达式和语句
C/C++ Table of contents 1. 2. 3. 4. C C++ 5. 6. 7. 1 i // shoe1.c: # include # define ADJUST 7. 64 # define SCALE 0. 325 int main ( void ) { double shoe, foot ; shoe = 9. 0; foot = SCALE * shoe
C/C++语言 - 分支结构
C/C++ Table of contents 1. if 2. if else 3. 4. 5. 6. continue break 7. switch 1 if if i // colddays.c: # include int main ( void ) { const int FREEZING = 0; float temperature ; int cold_ days
C/C++ - 字符串与字符串函数
C/C++ Table of contents 1. 2. 3. 4. 1 char C 2 char greeting [50] = " How " " are " " you?"; char greeting [50] = " How are you?"; 3 printf ("\" Ready, go!\" exclaimed John."); " Ready, go!" exclaimed
C
C 2017 4 1 1. 2. while 3. 4. 5. for 6. 2/161 C 7. 8. (do while) 9. 10. (nested loop) 11. 12. 3/161 C 1. I 1 // summing.c: 2 #include 3 int main(void) 4 { 5 long num; 6 long sum = 0L; 7 int status;
3.1 num = 3 ch = 'C' 2
Java 1 3.1 num = 3 ch = 'C' 2 final 3.1 final : final final double PI=3.1415926; 3 3.2 4 int 3.2 (long int) (int) (short int) (byte) short sum; // sum 5 3.2 Java int long num=32967359818l; C:\java\app3_2.java:6:
untitled
不 料 料 例 : ( 料 ) 串 度 8 年 數 串 度 4 串 度 數 數 9- ( ) 利 數 struct { ; ; 數 struct 數 ; 9-2 數 利 數 C struct 數 ; C++ 數 ; struct 省略 9-3 例 ( 料 例 ) struct people{ char name[]; int age; char address[4]; char phone[]; int
6 C51 ANSI C Turbo C C51 Turbo C C51 C51 C51 C51 C51 C51 C51 C51 C C C51 C51 ANSI C MCS-51 C51 ANSI C C C51 bit Byte bit sbit
6 C51 ANSI C Turbo C C51 Turbo C C51 C51 C51 C51 C51 C51 C51 C51 C51 6.1 C51 6.1.1 C51 C51 ANSI C MCS-51 C51 ANSI C C51 6.1 6.1 C51 bit Byte bit sbit 1 0 1 unsigned char 8 1 0 255 Signed char 8 11 128
untitled
Introduction to Programming ( 數 ) Lecture 3 Spring 2005 March 4, 2005 Lecture 2 Outline 數 料 If if 狀 if 2 (Standard Output, stdout): 料. ((Standard Input, stdin): 料. 類 數 數 數 說 printf 見 數 puts 串 數 putchar
CC213
: (Ken-Yi Lee), E-mail: [email protected] 9 [P.11] : Dev C++ [P.12] : http://c.feis.tw [P.13] [P.14] [P.15] [P.17] [P.23] Dev C++ [P.24] [P.27] [P.34] C / C++ [P.35] 10 C / C++ C C++ C C++ C++ C ( ) C++
int *p int a 0x00C7 0x00C7 0x00C int I[2], *pi = &I[0]; pi++; char C[2], *pc = &C[0]; pc++; float F[2], *pf = &F[0]; pf++;
Memory & Pointer [email protected] 2.1 2.1.1 1 int *p int a 0x00C7 0x00C7 0x00C7 2.1.2 2 int I[2], *pi = &I[0]; pi++; char C[2], *pc = &C[0]; pc++; float F[2], *pf = &F[0]; pf++; 2.1.3 1. 2. 3. 3 int A,
Microsoft Word - CPE考生使用手冊160524.docx
大 學 程 式 能 力 檢 定 (CPE) 考 生 使 用 手 冊 2016 年 5 月 24 日 這 份 手 冊 提 供 給 參 加 CPE 檢 定 考 試 的 考 生 內 容 包 含 考 試 環 境 的 使 用, 以 及 解 題 時 所 使 用 I/O 的 基 本 知 識 1. 如 欲 報 名 參 加 CPE 考 試, 請 先 於 CPE 網 站 完 成 帳 號 註 冊, 然 後 再 報 名 該
C/C++ - 数组与指针
C/C++ Table of contents 1. 2. 3. 4. 5. 6. 7. 8. 1 float candy [ 365]; char code [12]; int states [50]; 2 int array [6] = {1, 2, 4, 6, 8, 10}; 3 // day_mon1.c: # include # define MONTHS 12 int
四川省普通高等学校
四 川 省 普 通 高 等 学 校 计 算 机 应 用 知 识 和 能 力 等 级 考 试 考 试 大 纲 (2013 年 试 行 版 ) 四 川 省 教 育 厅 计 算 机 等 级 考 试 中 心 2013 年 1 月 目 录 一 级 考 试 大 纲 1 二 级 考 试 大 纲 6 程 序 设 计 公 共 基 础 知 识 6 BASIC 语 言 程 序 设 计 (Visual Basic) 9
1 2005 9 2005,,,,,,,,,, ( http: \ \ www. ncre. cn,, ) 30,,,,,,,, C : C : : 19 : 100081 : : 7871092 1 /16 : 8. 75 : 96 : 2005 11 1 : 2005 11 1 : ISBN 7
1 2005 9 2005,,,,,,,,,, ( http: \ \ www. ncre. cn,, ) 30,,,,,,,, C : C : : 19 : 100081 : : 7871092 1 /16 : 8. 75 : 96 : 2005 11 1 : 2005 11 1 : ISBN 7-80097 - 564-9 /TP 8 : 10. 00 ,,,, 1994 NCRE,,, ( ),,,,,
プログラムの設計と実現II
UNIX C ls mkdir man http://www.tj.chiba-u.jp/lecture/prog2/ Ctrl+x, Ctrl+s ( )..[4]% gcc Wall o hoge hoge.c..[5]%./hoge 1 : 1 2 : 2 3 : 3 4 : 0 6..[6]% (! )..[4]% gcc Wall o hoge hoge.c..[5]%!g gcc Wall
科学计算的语言-FORTRAN95
科 学 计 算 的 语 言 -FORTRAN95 目 录 第 一 篇 闲 话 第 1 章 目 的 是 计 算 第 2 章 FORTRAN95 如 何 描 述 计 算 第 3 章 FORTRAN 的 编 译 系 统 第 二 篇 计 算 的 叙 述 第 4 章 FORTRAN95 语 言 的 形 貌 第 5 章 准 备 数 据 第 6 章 构 造 数 据 第 7 章 声 明 数 据 第 8 章 构 造
C C C The Most Beautiful Language and Most Dangerous Language in the Programming World! C 2 C C C 4 C 40 30 10 Project 30 C Project 3 60 Project 40
C C [email protected] C C C C The Most Beautiful Language and Most Dangerous Language in the Programming World! C 2 C C C 4 C 40 30 10 Project 30 C Project 3 60 Project 40 Week3 C Week5 Week5 Memory & Pointer
1 Project New Project 1 2 Windows 1 3 N C test Windows uv2 KEIL uvision2 1 2 New Project Ateml AT89C AT89C51 3 KEIL Demo C C File
51 C 51 51 C C C C C C * 2003-3-30 [email protected] C C C C KEIL uvision2 MCS51 PLM C VC++ 51 KEIL51 KEIL51 KEIL51 KEIL 2K DEMO C KEIL KEIL51 P 1 1 1 1-1 - 1 Project New Project 1 2 Windows 1 3 N C test
ebook8-30
3 0 C C C C C C++ C + + C++ GNU C/C++ GNU egcs UNIX shell s h e l l g a w k P e r l U N I X I / O UNIX shell awk P e r l U N I X C C C C C C U N I X 30.1 C C U N I X 70 C C U N I X U N I X U N I X C Dennis
Microsoft Word - 09.數學136-281.docx
136. 計 算 梯 型 面 積 (1 分 ) 請 以 JAVA 運 算 式 計 算 下 面 梯 形 面 積, 並 輸 出 面 積 結 果 梯 形 面 積 公 式 為 :( 上 底 + 下 底 ) 高 2 每 一 組 依 序 分 別 輸 入 梯 形 的 上 底 下 底 及 高 的 整 數 輸 出 梯 形 面 積 輸 入 輸 出 94 190 120 99 54 47 137. 計 算 三 角 形 面
CC213
: (Ken-Yi Lee), E-mail: [email protected] 177 [P179] (1) - [P181] [P182] (2) - for [P183] (3) - switch [P184] [P187] [P189] [P194] 178 [ ]; : : int var; : int var[3]; var 2293620 var[0] var[1] 2293620
51 C 51 isp 10 C PCB C C C C KEIL
http://wwwispdowncom 51 C " + + " 51 AT89S51 In-System-Programming ISP 10 io 244 CPLD ATMEL PIC CPLD/FPGA ARM9 ISP http://wwwispdowncom/showoneproductasp?productid=15 51 C C C C C ispdown http://wwwispdowncom
untitled
A, 3+A printf( ABCDEF ) 3+ printf( ABCDEF ) 2.1 C++ main main main) * ( ) ( ) [ ].* ->* ()[] [][] ** *& char (f)(int); ( ) (f) (f) f (int) f int char f char f(int) (f) char (*f)(int); (*f) (int) (
untitled
1 Outline 數 料 數 數 列 亂數 練 數 數 數 來 數 數 來 數 料 利 料 來 數 A-Z a-z _ () 不 數 0-9 數 不 數 SCHOOL School school 數 讀 school_name schoolname 易 不 C# my name 7_eleven B&Q new C# (1) public protected private params override
, 7, Windows,,,, : ,,,, ;,, ( CIP) /,,. : ;, ( 21 ) ISBN : -. TP CIP ( 2005) 1
21 , 7, Windows,,,, : 010-62782989 13501256678 13801310933,,,, ;,, ( CIP) /,,. : ;, 2005. 11 ( 21 ) ISBN 7-81082 - 634-4... - : -. TP316-44 CIP ( 2005) 123583 : : : : 100084 : 010-62776969 : 100044 : 010-51686414
untitled
MODBUS 1 MODBUS...1 1...4 1.1...4 1.2...4 1.3...4 1.4... 2...5 2.1...5 2.2...5 3...6 3.1 OPENSERIAL...6 3.2 CLOSESERIAL...8 3.3 RDMULTIBIT...8 3.4 RDMULTIWORD...9 3.5 WRTONEBIT...11 3.6 WRTONEWORD...12
Ps22Pdf
( 98 ) C ( ) ( )158 1998 C : C C C,,, C,, : C ( ) : : (, 100084) : : : 7871092 1/ 16 :18 25 :415 : 2000 3 1 2000 3 1 : ISBN 7 302 01166 4/ T P432 : 00016000 : 22 00 ( 98 ) 20 90,,, ;,,, 1994, 1998, 160,
2013 C 1 # include <stdio.h> 2 int main ( void ) 3 { 4 int cases, a, b, i; 5 scanf ("%d", & cases ); 6 for (i = 0;i < cases ;i ++) 7 { 8 scanf ("%d %d
2013 18 ( ) 1. C pa.c, pb.c, 2. C++ pa.cpp, pb.cpp, Compilation Error cin scanf Time Limit Exceeded 1: A 5 B 5 C 5 D 5 E 5 F 5 1 2013 C 1 # include 2 int main ( void ) 3 { 4 int cases, a, b,
C PICC C++ C++ C C #include<pic.h> C static volatile unsigned char 0x01; static volatile unsigned char 0x02; static volatile unsigned cha
CYPOK CYPOK 1 UltraEdit Project-->Install Language Tool: Language Suite----->hi-tech picc Tool Name ---->PICC Compiler Executable ---->c:hi-picinpicc.exe ( Command-line Project-->New Project-->File Name--->myc
全国计算机技术与软件专业技术资格(水平)考试
全 国 计 算 机 技 术 与 软 件 专 业 技 术 资 格 ( 水 平 ) 考 试 2008 年 上 半 年 程 序 员 下 午 试 卷 ( 考 试 时 间 14:00~16:30 共 150 分 钟 ) 试 题 一 ( 共 15 分 ) 阅 读 以 下 说 明 和 流 程 图, 填 补 流 程 图 中 的 空 缺 (1)~(9), 将 解 答 填 入 答 题 纸 的 对 应 栏 内 [ 说 明
Python a p p l e b e a r c Fruit Animal a p p l e b e a r c 2-2
Chapter 02 變數與運算式 2.1 2.1.1 2.1.2 2.1.3 2.1.4 2.2 2.2.1 2.2.2 2.2.3 type 2.2.4 2.3 2.3.1 print 2.3.2 input 2.4 2.4.1 2.4.2 2.4.3 2.4.4 2.4.5 + 2.4.6 Python Python 2.1 2.1.1 a p p l e b e a r c 65438790
Microsoft PowerPoint - OPVB1基本VB.ppt
大 綱 0.VB 能 做 什 麼? CH1 VB 基 本 認 識 1.VB 歷 史 與 版 本 2.VB 環 境 簡 介 3. 即 時 運 算 視 窗 1 0.VB 能 做 什 麼? Visual Basic =>VB=> 程 式 設 計 語 言 => 設 計 程 式 設 計 你 想 要 的 功 能 的 程 式 自 動 化 資 料 庫 計 算 模 擬 遊 戲 網 路 監 控 實 驗 輔 助 自 動
( CIP. :, 2004. 10 / ISBN 7-5054 - 1005-9.......... D630. 3-44 CIP ( 2004 055306 35 100044 ( 010) 68433166 ( ) ( 010) 68413840 /68433213( ) ( 010) 884
, : :,, : ( CIP. :, 2004. 10 / ISBN 7-5054 - 1005-9.......... D630. 3-44 CIP ( 2004 055306 35 100044 ( 010) 68433166 ( ) ( 010) 68413840 /68433213( ) ( 010) 88415258( ) 787 1092 1 / 16 195 8 2004 10 1
C
C 14 2017 5 31 1. 2. 3. 4. 5. 2/101 C 1. ( ) 4/101 C C ASCII ASCII ASCII 5/101 C 10000 00100111 00010000 ASCII 10000 31H 30H 30H 30H 30H 1 0 0 0 0 0 ASCII 6/101 C 7/101 C ( ) ( ) 8/101 C UNIX ANSI C 9/101
C, Win-TC Turbo C,, C, C,,,, C C, : Win-TC C, 23,,, 15,, C Turbo C Win-TC Turbo C,,,, 2005 1 W in -TC 1 Win-TC 1 1. Win-TC 1 2. Win-TC 1 3. Win-TC 1 2 Win-TC 3 1. 3 2. 3 3. 4 4. 4 5. 4 6. 4 7. 5 8. 5 9.
CIP 1500 / ISBN X Ⅰ. Ⅱ. Ⅲ. Ⅳ. D CIP edu. cn
1500 CIP 1500 /. 2006. 8 ISBN 7 5625 2128X Ⅰ. Ⅱ. Ⅲ. Ⅳ. D920. 5 44 CIP 2006 087648 1500 388 430074 027 87482760 027 87481537 E-mail cbb@cug. edu. cn 2006 8 1 2006 8 1 850 1 168 1 /32 8. 625 220 26. 00 1.
bingdian001.com
TSM12M TSM12 STM8L152C6, STM8L152R8 MSP430F5325 [email protected]! /******************************************************************************* * : TSM12.c * : * : 2013/10/21 * : TSM12, STM8L f(sysclk)
Microsoft Word - 01.DOC
第 1 章 JavaScript 简 介 JavaScript 是 NetScape 公 司 为 Navigator 浏 览 器 开 发 的, 是 写 在 HTML 文 件 中 的 一 种 脚 本 语 言, 能 实 现 网 页 内 容 的 交 互 显 示 当 用 户 在 客 户 端 显 示 该 网 页 时, 浏 览 器 就 会 执 行 JavaScript 程 序, 用 户 通 过 交 互 式 的
EK-STM32F
STMEVKIT-STM32F10xx8 软 件 开 发 入 门 指 南 目 录 1 EWARM 安 装... 1 1.1 第 一 步 : 在 线 注 册... 1 1.2 第 二 步 : 下 载 软 件... 2 1.3 第 三 步 : 安 装 EWARM... 3 2 基 于 STMEVKIT-STM32F10xx8 的 示 例 代 码 运 行... 6 2.1 GPIO Demo... 6 2.2
1 LINUX IDE Emacs gcc gdb Emacs + gcc + gdb IDE Emacs IDE C Emacs Emacs IDE ICE Integrated Computing Environment Emacs Unix Linux Emacs Emacs Emacs Un
Linux C July 27, 2016 Contents 1 Linux IDE 1 2 GCC 3 2.1 hello.c hello.exe........................... 5 2.2............................... 9 2.2.1 -Wall................................ 9 2.2.2 -E..................................
1 4 1.1 4 1.2..4 2..4 2.1..4 3.4 3.1 Java.5 3.1.1..5 3.1.2 5 3.1.3 6 4.6 4.1 6 4.2.6 5 7 5.1..8 5.1.1 8 5.1.2..8 5.1.3..8 5.1.4..9 5.2..9 6.10 6.1.10
Java V1.0.1 2007 4 10 1 4 1.1 4 1.2..4 2..4 2.1..4 3.4 3.1 Java.5 3.1.1..5 3.1.2 5 3.1.3 6 4.6 4.1 6 4.2.6 5 7 5.1..8 5.1.1 8 5.1.2..8 5.1.3..8 5.1.4..9 5.2..9 6.10 6.1.10 6.2.10 6.3..10 6.4 11 7.12 7.1
Microsoft Word - PHP7Ch01.docx
PHP 01 1-6 PHP PHP HTML HTML PHP CSSJavaScript PHP PHP 1-6-1 PHP HTML PHP HTML 1. Notepad++ \ch01\hello.php 01: 02: 03: 04: 05: PHP 06:
Ps22Pdf
( ) ,,,,,,,,,,, (CIP). () /. 2 :, 2003. 9 ISBN 7-81045 - 824-8... - : -. G723.4 - CIP (2001)029424 / / 5 / 100081 / (010 ) 68914775 () 68912824 ( ) / http:/ / www. bitpress. com. cn / chiefedit @bitpress.
:,,,,,,, ( CIP) /,. :, 2002. 8 ISBN 7-5624-2708-9............ :. F590. 63 CIP ( 2002) 062616 : : * : : : : 174 ( A ) : 400044 : ( 023) 65102378 651057
:,,,,,,, ( CIP) /,. :, 2002. 8 ISBN 7-5624-2708-9............ :. F590. 63 CIP ( 2002) 062616 : : * : : : : 174 ( A ) : 400044 : ( 023) 65102378 65105781 : ( 023) 65103686 65105565 : http: / / www. cqup.
C语言的应用.PDF
AVR C 9 1 AVR C IAR C, *.HEX, C,,! C, > 9.1 AVR C MCU,, AVR?! IAR AVR / IAR 32 ALU 1KBytes - 8MBytes (SPM ) 16 MBytes C C *var1, *var2; *var1++ = *--var2; AVR C 9 2 LD R16,-X ST Z+,R16 Auto (local
概述
OPC Version 1.6 build 0910 KOSRDK Knight OPC Server Rapid Development Toolkits Knight Workgroup, eehoo Technology 2002-9 OPC 1...4 2 API...5 2.1...5 2.2...5 2.2.1 KOS_Init...5 2.2.2 KOS_InitB...5 2.2.3
<4D F736F F D D342DA57CA7DEA447B14D2DA475B57BBB50BADEB27AC3FEB14DA447B8D5C344>
1. 請 問 誰 提 出 積 體 電 路 (IC) 上 可 容 納 的 電 晶 體 數 目, 約 每 隔 24 個 月 (1975 年 更 改 為 18 個 月 ) 便 會 增 加 一 倍, 效 能 也 將 提 升 一 倍, 也 揭 示 了 資 訊 科 技 進 步 的 速 度? (A) 英 特 爾 (Intel) 公 司 創 始 人 戈 登. 摩 爾 (Gordon Moore) (B) 微 軟 (Microsoft)
untitled
1 7 7.1 7.2 7.3 7.4 7.5 2 7.1 VFT virtual 7.1 3 1 1. 2. public protected public 3. VFT 4. this const volatile 4 2 5. ( ) ( ) 7.1 6. no-static virtual 7.2 7. inline 7.3 5 3 8. this this 9. ( ) ( ) delete
WWW PHP
WWW PHP 2003 1 2 function function_name (parameter 1, parameter 2, parameter n ) statement list function_name sin, Sin, SIN parameter 1, parameter 2, parameter n 0 1 1 PHP HTML 3 function strcat ($left,
Spyder Anaconda Spyder Python Spyder Python Spyder Spyder Spyder 開始 \ 所有程式 \ Anaconda3 (64-bit) \ Spyder Spyder IPython Python IPython Sp
01 1.6 Spyder Anaconda Spyder Python Spyder Python Spyder Spyder 1.6.1 Spyder 開始 \ 所有程式 \ Anaconda3 (64-bit) \ Spyder Spyder IPython Python IPython Spyder Python File
Progperl.PDF
print "Howdy, world!\n"; 1 2 / / 3 4 / $phrase = " Howdy, world!\n"; print $phrase ; # # / 5 6 / $answer = 42; $pi = 3.14159265; $avocados = 6.02e23; $pet = "Camel"; $sign = "I love my $pet"; $cost = 'It
C++ 程式設計
C C 料, 數, - 列 串 理 列 main 數串列 什 pointer) 數, 數, 數 數 省 不 不, 數 (1) 數, 不 數 * 料 * 數 int *int_ptr; char *ch_ptr; float *float_ptr; double *double_ptr; 數 (2) int i=3; int *ptr; ptr=&i; 1000 1012 ptr 數, 數 1004
第7章-并行计算.ppt
EFEP90 10CDMP3 CD t 0 t 0 To pull a bigger wagon, it is easier to add more oxen than to grow a gigantic ox 10t 0 t 0 n p Ts Tp if E(n, p) < 1 p, then T (n) < T (n, p) s p S(n,p) = p : f(x)=sin(cos(x))
untitled
1 Outline 流 ( ) 流 ( ) 流 ( ) 流 ( ) 流 ( ) 狀 流 ( ) 利 來 行流 if () 立 行 ; else 不 立 行 ; 例 sample2-a1 (1) 列 // 料 Console.Write(""); string name = Console.ReadLine(); Console.WriteLine(" " + name + "!!"); 例 sample2-a1
6-1 Table Column Data Type Row Record 1. DBMS 2. DBMS MySQL Microsoft Access SQL Server Oracle 3. ODBC SQL 1. Structured Query Language 2. IBM
CHAPTER 6 SQL SQL SQL 6-1 Table Column Data Type Row Record 1. DBMS 2. DBMS MySQL Microsoft Access SQL Server Oracle 3. ODBC SQL 1. Structured Query Language 2. IBM 3. 1986 10 ANSI SQL ANSI X3. 135-1986
(CIP) : /. :, 2004 ISBN T S CIP (2004) (1 : ) : * : : :
(CIP) : /. :, 2004 ISBN 7 5045 4510 4.... T S974. 2 CIP (2004) 044759 (1 : 100029 ) : * 787 1092 16 8. 25 176 2004 6 1 2004 6 1 : : 15. 00 : 010 64929211 : 010 64911190 : http: / / www. class. com. cn
( ) A B C D ( ) A B C D A B C D A B C D A 8750 B C 6250 D 5000 A B C D A B C D
1 A B C D A B C D A B C D 1000 1200 900 A B C D ( ) A B C D ( ) A B C D A B C D A B C D 5000 6250 A 8750 B 11250 C 6250 D 5000 A B C D A B C D A B C D 1 200000 400 10 A 1000 B 1600 C 2000 D 2300 1 A B
FZUBRIDGE
1 2 3 5 8 9 10 11 12 13 14 15 16 17 19 20 21 23 24 25 29 31 32 33 34 M g1 M 1g ( M 2g M 1g )(1 e ( t, ) ) 35 36 M Q M Q g g 1.15M 1.05Q p p 37 max 1 n e max n i1 1 2 i 38 39 n max M Q M Q g g
图书在版编目 CIP 数据 李济深与苍梧故居 / 民革中央宣传部编. -- 北京 团结出版社 2013.6 ISBN 978-7-5126-1916-6 Ⅰ. ①李 Ⅱ. ①民 Ⅲ. ①李济深 1885~1959 传记②名人 故居 介绍 苍梧县 Ⅳ. ① K827=7②K878.2 中国版本图书馆C
丛书编委会 总 顾 问 周铁农 万鄂湘 齐续春 顾 问 朱培康 卞晋平 常荣军 尚明轩 编委会主任 修福金 编委会委员 程崇庆 傅惠民 周天鸿 刘新文 高小玫 夏 涛 李晓东 吴先宁 丛 书 主 编 王秉默 执 行 委 员 刘则永 刘玉霞 金绮寅 1 图书在版编目 CIP 数据 李济深与苍梧故居 / 民革中央宣传部编. -- 北京 团结出版社 2013.6 ISBN 978-7-5126-1916-6
untitled
2006 6 Geoframe Geoframe 4.0.3 Geoframe 1.2 1 Project Manager Project Management Create a new project Create a new project ( ) OK storage setting OK (Create charisma project extension) NO OK 2 Edit project
untitled
MPICH [email protected] 1 MPICH for Microsoft Windows 1.1 MPICH for Microsoft Windows Windows NT4/2000/XP Professional Server Windows 95/98 TCP/IP MPICH MS VC++ 6.x MS VC++.NET Compaq Visual Fortran 6.x
( CIP ) /. - :, ( ) ISBN , -. K CIP ( 1999 ) * ( 6 ) : * ISBN :
( CIP ) /. - :, 1999.10 ( ) ISBN 7-200 - 03791-5..., -. K892. 41 CIP ( 1999 ) 32680 * ( 6 ) : 100011 * 199 1 199 1 ISBN : 1997 2 10, :, :,,,,,,,,,,,, 1984,,,,,,, 1 ,,?,, 2 ( 1 ) ( 3 ) 1. ( 3 ) 2. ( 7 )
C 1 # include <stdio.h> 2 int main ( void ) { 4 int cases, i; 5 long long a, b; 6 scanf ("%d", & cases ); 7 for (i = 0;i < cases ;i ++) 8 { 9
201 201 21 ( ) 1. C pa.c, pb.c, 2. C++ pa.cpp, pb.cpp Compilation Error long long cin scanf Time Limit Exceeded 1: A 1 B 1 C 5 D RPG 10 E 10 F 1 G II 1 1 201 201 C 1 # include 2 int main ( void
