Ps22Pdf
|
|
|
- 久 章
- 9 years ago
- Views:
Transcription
1 C
2 ( CIP) C /. :, ISBN C C. TP312 CIP ( 2001 ) C * * : /16 : : : ISBN / TP311 :
3 C, C,,,, C,, ( ),, ( ), C C ++ JAVA, C,, C,,,,,,, 1, C, 2 C 3 5 C, C,,, 1
4 C 6 7, 8,, 9, 10, 11 C ASCII C, C,,,, C,,,,,, 1 11,,,,,, 87 ANSI C,,, MS-DOS Windows MS-DOS Turbo C, UNIX C,, : ( ), ( 2 4 ), ( 8 10 ), ( 11 ). ( ),,,,,,,,
5 1 C C C C C C C goto 55 1
6 C main C C C
7 typedef C A ASCII 209 B C 210 C C 210 D C 214 3
8 1 C, C C,, C, C C, 1. 1 C C 1969, ( Bell Laboratories) Ken Thompson D. M. Rithie UNIX 1970, Ken Thompson UNIX, BCPL ( ALGOL 60 CPL ) B 1973, D. M. RithieB C, K. Thompson D. M. Rithie C UNIX 1978, B. W. Kernighan D. M. Rithie The C Programming Language C, CC, C, ( ),, ( ), C 1987, ( ANSI) C 87 ANSI C, 1990, ISO 87 ANSI C ISO C C DOS MS C5. 0 Turbo C 2. 0, UNIX UNIX 4. 2BSD, C C ++ C, C ++ C, C ++ C, C C ++ Borland C ++ Visual C ++ JAVA C, C, 1
9 C C C : C,,, ( 10 % 20% ) C,,, C, C, C C, 34, C, C #, C,,, ( ),,, 1. 2 C C, C C 1. 1 #include stdio. h { printf( Good morning! \ n ) ; printf( * * * * * * * * * * * * * * * \ n ) ; : Good morning! * * * * * * * * * * * * * * *, #include stdio. h, stdio. h, C printf( ), C {, printf( ), 2
10 1 C \n, 1. 2 #include stdio. h / *, C * / { int r; / *, r ( int ) * / float area; / *, area ( float ) * / printf( Input r: ) ; / * r, * / scanf( % d, &r) ; / * scanf( ), r * / area = * r* r; / *, area * / printf( area = % f\ n, area) ; / *, area =, \n * / : Input r: 10 area = :,, / * * /,,, 1. 3 #include stdio. h / *, C * / { int a, b, c; / *, a, b, c int * / int max( int x, int y) ; / * int max, 2, int * / / * * / printf( Input a, b: ) ; / * a, b, * / scanf( % d, % d, &a, &b) ; / * 2 a b, * / c = max( a, b) ; / * max( ), c * / printf( max = % d \ n, c) ; / * c * / int max( int x, int y) / * max( ), int, x, y int * / { int z; / * int z * / if ( x > y) else z = y; z = x; return z; / * z * / : Input a, b: 16, 20 max = 20 2, main max, ( ) max, a, b 3
11 C max x, ymax z C, C : C, 1. 3, C : { ; ;,, C,, ; C, sum, mean, #include, #, ;, / * * /,,, C ( C ) 3 scanf( ) printf( ), 1. 3 max( ),, : ( ) { ; ;, ,,,,,, 4
12 1 C 1. 3,, ( 1 )?,,,,,,,,, , : 1, 100 ; 2,, : 1 ; 2 ; ; 3 ; ; 4 ; 100 ; ; 100, ;, 1 000,,,,,, 100, : sum,,, sum, sum = 0 c, mean,,, n,,, n, n = 0 5
13 C : sum0 ; n0; c; c sum, c + sumsum( ) ; n 1, n + 1n( ) ; n < 100, ( n < ,, n 100, 100, a, ) ; sum /n, mean, sum / nmean; mean,,, , n < 100 n < 1000 ( 2 ), , 1. 2 Y 1. 1 N sum= 0 n= 0 c sum= sum+ c n= n+ 1 n< 100 mean= sum n mean 1. 4 ( ),, ( ), ( ), 1. 2,,, ( ),, 1. 1 sum = 0 n = 0 0 sum sum0 = 0 0 sum sum ,, ch, :
14 1 C ch; ch ( \ n ), ; ch a ch z ch - ( a - A ) ch ch, ch ; ; ch ; ;,, ch 1. 3 : Y 1. 6 s = 3! + 5! + 7! + 9! s, n!, n = 3, 5, 7, 9 s = 0 ; n = 3; s = s + n! ; n = n + 2; n9,, ; s= 0 n= 3 fact( n) s= s+ n! n= n+ 2 n9 s N 1. 4 fact( x) i= 1 m= 1 ix Y m= m* i i= i+ 1 m 1. 6 N 1. 3 s; ch ch n Y Y ch ch ch N N 1. 5 n!? fact( x), x = n, fact ( n ) n! n!, fact( n) fact( x) ( m, i, i = 1, 2, 3,, x) : i = 1; m = 1 ; ix, ; m = m* i; i = i + 1 ; ; m 1. 4 ( 3 ) : 7
15 C,, ( ), 0 1 0, C C, 8 C 3 ( 1 ) 1. 4 C #include stdio. h / *, C * / { int c, n; / *, c, n ( int ) * / float sum, mean; / *, sum, mean ( float ) * / sum = 0; n = 0; / *, * / / * sum n * / do{ / * do{ while * / scanf( % d, &c) ; / * c* / sum = sum + c; / * * / n = n + 1; / * * / while( n < 100) ; / * * / mean = sum / n; / * * / printf( average = % f\ n, mean) ; /*, average =, \ n * / ( 2 ) 1. 5 C #include stdio. h / *, stdio. h, getchar( ) putchar( ) * / { char ch; / * ch ( char ) * / while ( ( ch = getchar( ) )! / * * / = \ n ) / * while, : ch * / { if ( ch >= a&& ch <= z ) / * if * / ch = ch - ( a - A ) ; / * ch, * / putchar( ch) ; / * * / printf( \ n ) ; / * * /
16 1 C : Good morning! GOOD MORNING!, while, {, { ( ), for, {, ( 3 ) 1. 6 C #include stdio. h /*, C * / { int n; /*, n int * / long s, fact( int) ; / * s long, long fact,, int * / for( s = 0, n = 3; n <= 9; n = n + 2) /* for, n = 3, 5, 7, 9, 4 * / s = s + fact( n) ; /* fact( x) * / printf( 3! + 5! + 7! + 9! = % ld \ n, s) ; /* s* / long fact( int x) / * fact( x), long, x int * / { long m = 1; / *, m i long int, m * / int i; / * * / for( i = 1; i < = x; i + + ) / * for, i = 1, 2, 3,, x, x * / m = m* i; / * i * / return m; / * m * / : 3! + 5! + 7! + 9! = long, s m fact int :,,, C, ; C, ; C if for while do-while,, C,,, 9
17 C 1. 4 C, C,,, C : A. ASCII C C,. c, test. c B.,, UNIX. o, MS-DOS. obj, CP / M. CRL,,,, C.,,,,, UNIX. out, MS-DOS. exe, CP/ M. com D.,,,,, C : * * * * * * * * * * * * * * * * * Welcome! * * * * * * * * * * * * * * * * * 1. 2,, 1. 3 s = ,, C 1. 4, :,,,, 64, :! C,? ( 1m ) 1. 5 e ! + 1 2! e ( n n! ),, C C
18 1 C 1. 7 C C C 11
19 2 ( Nikiklaus Wirth) : + =, : C, :, C : int char float double, void C, C, C 12
20 C C C 5 : char intfloat double void void 4 char: 1 1 ASCII int: 2 4 1, PC 2 float: 4 1 double: 8 1 void:,, void, 4, C : signed( ) unsigned( ) long( ) short( ) 4 signed unsigned short long char int, long double Turbo C ++ / bit char unsigned char signed char char int unsigned int unsigned signed int int signed unsigned short int unsigned short signed short int short long int long signed long int long unsigned long int unsigned long float e e + 38 double e e long double e e
21 C signed int,, int ( signed) ( signed) ( unsigned), : 0, ; 1,, short long int, 16 32, short int long int 16 32, long int , int int, int PC, int short int, 2 long C,,, C ( 1 ),, C 0 x, 0, : x = 0 xff; / * 255 * / y = 011; / * 9* /,, 2 : ( short int) ( int) ( long int) ( unsigned),, 2. 1, L U 123L, 4 123U int, 123LU long ( 2 ) C, : ( ), : ; e( E) 1 3, : e e e
22 2,, 4,,, ( bit), ( ), :,, z, 4, #, ( ) C ( ),, 2. 2, ASCII, 1 1, A ASCII 65, A \ 101 \ x41 A, ASCII, 65, 0x41, , 0 255,, A 65, A \0 NULL \ a BELL \ b BS \ f FF \ n NL( LF) \ r CR \ t HT ( TAB) \ v VT \ \ \ \ \ \ddd 1 3 \ xhh C, 15
23 C, This is a test,,,, ASCII C NULL( \0 ), n, n + 1, HELLO 5, 6, : H E L L O \0, a, a a, C,, ( ) C : const ( 1 ), : #define : #define PI PI ,,, #define C, ; PI ( ),, ; ,,,,, ( ), ( 2 ) const ( ) const, const,, : const = ; C, : const double pi = ; piconst ( ), const, 16
24 2 const :,, ;,, #define, const #define const ( ), #define, const,,, #define C ( 1 ) C : C,, C, count, Count, COUNT 3, ANSI ( Turbo C) 31,, 32, 33,, C 3 : 1 ) C : asm, auto, break, case, cdecl, char, const, continue, default, do, double, else, enum, extern, far, float, for, goto, huge, if, interrupt, int, long, near, pascal, register, return, short, signed, sizeof, static, struct, switch, typedef, union, unsigned, void, volatile, while int, int1 Int INT 2 ) C, ( printf) ( define) C,, 3 ) ( 2 ),,,, 17
25 C, : fmem: free memory available,,,,,,, ( ), 2. 3, selected char c cinchar disk drive; int i ireturnvalue, long l lnumrecs SelectedDiskDrive, string sz szinputstring int array ai aierrornumber,, char * psz pszinputstring, Microsoft Charles Simonyi 2. 3 Microsoft Windows,, Visual Basic Acess,,,,, Microsoft Windows,, C,,, : ;, C, ( ) : int x, y; / * int x, y * / float average; / * float average * / unsigned int z; / * unsigned int z * / double pi; / * double pi * / long m, n; / * long m, n * / 18
26 , : = ; : { int event = 5; char heat = C ; float time = 27. 5; : printf( The winning time in heat % c, heat) ; printf( of event % d was % f., event, time) ; The winning time in heat C of event 5 was 27. 5, C,, printf( ) : printf(, ) ;, : % d % o % x % u % c % s % f printf( ),,,, printf( ), 19
27 C, printf( ),,, : printf ( % s% d \ n, this is a string, 100) ; this is a string 100 printf ( this is a string % d \ n, 100) ; this is a string 100 printf ( % d is int, % f is float. \ n, 10, ) ; 10 is int, is float printf ( % s \ n, HELLO ) ; HELLO scanf( ) C, scanf( ) : scanf (, ) ;, : % d % o % x % c % s % f : & &a &x,, scanf( ), Tab scanf( ) { int a, b; printf( Enter integer a and b: ) ; scanf( % d% d, &a, &b) ; printf( a + b = % d \ n, a + b) ; printf( a - b = % d \ n, a - b) ; : Enter integer a and b: 6 3
28 2 a + b = 9 a - b = 3, scanf ( ) 2,, 2, a b, scanf ( ), : scanf ( % d, % d, &a, &b) ;,, : 6, 3,, & C + ( ) - ( ) * ( ) / ( ) % ( ), C, ++ ( ) - - ( ) ( ), C, /,, 10 / %,,% - 1,, 2. 2 #include < stdio. h > { int x, y; : printf( enter dividend and divisor: ) ; / * * / scanf( % d, % d, &x, &y) ; printf( quotient % d \ n, x / y) ; / * * / printf( remainder % d, x% y) ; / * * / enter dividend and divisor: 23, 5 quotient 4 remainder C, , 21
29 C, 1 1, ++ 1, : x ++ ; ++ x; x = x + 1; x - - ; - - x; x = x - 1; ++ x x + 1, x ++ x + 1 x, - - x x - 1, x - - x - 1 x x = 100, : x ++ x x ++ x - - x x - - x , 2. 3 { int a = 25, b = 80, aa, bb; a ++ ; b--; : aa = ++ a; bb = --b; printf( a = % d, b = % d, aa = % d, bb = % d \n, a, b, aa, bb) ; aa = a ++ ; bb = b--; printf( a = % d, b = % d, aa = % d, bb = % d \n, a, b, aa, bb) ; a = 27, b = 78, aa = 27, bb = 78 a = 28, b = 77, aa = 27, bb = 78, C, C,,, ,,,,,,,,,,, : c = ( ++ a% b-- + c) /d - 6* e : % + / * - =
30 C, C, : 0, 0,, 0, ; 0,,, C 2. 4 C :,, 0 ( ) 1 ( ) 2. 4 C > b > c b c >= b >= c b c == b == c b c <= b <= c b c < b < c b c! = b! = c b c, greater ch1 = A ; ch2 = B ; if ( ch2 > ch1) printf( great than ) ; than, ASCII, B A,, > >= < <= ==! =, x + 8 > y* 10, x + 8 y* 10, , : const float first = 0. 0; const float last = 70. 0; const float small = ; if( ( first + small* 10000) == last) ( first + small* 10000) == last, 1( ),, small ( first + small* ) last, 0( ) : if( abs( first + small* last) < 1e - 6) ( 10-6 ), 23
31 C 2. 7, 3 : ( &&) ( ) (! ),, 1,0 ( 2. 5 ) 2. 5 p q p && q pq! p : 10 > 5 &&! ( 10 < 9) 3 >= 4 C, :! ( ), &&( ), ( ) : a + b > cd &&! e :! + > &&! ( 10 < 9), 1, 10 > 5&&! ( 10 < 9), 1, 3 <= 4, 1( ), if, if #include < stdio. h > { int i; for ( i = 1; i <= 100; i ++ ) if (! ( i% 2) ) printf( % d, i) ; /* i, i% 2 0,! ( i% 2) 1 * / C, C, C : = 24 =, ( ) : a = c ++ ; / * * / b = x* y + 5; / * * /
32 2 e = a > b; / * * /,,, ;,, C : x = y = z = 2; x = ( y = ( z = 2) ) ; z = 2, 2 x, z = 2 2, y, y = z = 2 2, x, 2, : f = a = b + 3; / * f = ( a = b + 3) ; * /, C : if ( ( product = x* y) < 0) else printf( one number is negative \ n ) ; printf( positive product is: % d, product ) ; if, x* y product, 0, 1( ) 0( ) = 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 C, 2. 6,, , C
33 C 2. 7 ( ) ( ) int char 8, 8 0 char int int 8 char, int long int int float, double float double double double float float double 2. 9 : C, 3 1? 2: 3 (? ) ( : ) : 1, 0( ), 2 ; 0 ( ), 3 : x = ( a > b)? a: b; / * a b x * / y = ( x >= 0)? x: - x; / * x * / c = ( c >= a&& c <= z )? c - 32: c; / * c * / t? printf( % d, t) : printf( zero entered ) ; / * 0, printf( ), zero entered ;, * /,, : sgn = ( x > 0)? 1: ( x < 0? - 1: 0) /* x, 1, - 1, 0 0 * / , :,, int x = 3, y = 5; float z = 10. 0, a; a = x /y* z 26
34 2 a x / y x y, x / y , C : char short unsigned short long unsigned long float double long double,, 2. 7, ,, : char ch; int i; long l; float f; double d; : result= ( ch i ) + ( f * d ) - ( f + i ) ; int double double int double double double double double result float, float resultresult int, int result : ( ), C,, : ( int) x % n / * x int, * / ( int) sqrt( ( double) n) / * n double, sqrt int * /, ( int) x / y ( int) ( x /y), x, x / y,, : 27
35 C #include < stdio. h > { int i = 3; int j = 4; float f1 = i / j; float f2 = ( float) i / j; printf( 3 /4 = % f or % f depending on the type used. \ n, f1, f2) ; f1 i j,, 0 f2 i j, ( float) i float,, 0. 75,,, : #include < stdio. h > { int i; for( i = 1; i <= 100; ++ i) printf( % d /3 is : % f\ n, i, ( float) i /3) ; ( float),,,, void *, void, malloc ( ) student : struct student * p; p = ( struct student * ) malloc( sizeof( struct student) ) ; 2. 11, : 1, 2,, n, :, : x = ( y = 3, y + 1) ; 28
36 2, y 3, y + 1, 4, 4 ( y = 3, y + 1) x : printf( % d \n, ( 3 + 5, 15) ) ; / * 3 + 5, * / printf( % d, % d \ n, 3 + 5, 15) ; / * * /, C 9,,, : ( ) ( * / % ) ( + - ) ( ) ( < <= > >= ) (! = == ) ( & ) ( && ) (? : ) ( ), C,, 2. 8 C 1 ( ) [ ] - >. 2! * & sizeof 3 * / % < <= > >= 7! = == 8 & && 12 13?: 14 = + = - = * = / = % = & = =! = = = 15,, : a = b + c /d / fun( ) * 5,, : 29
37 C a = b + ( ( ( c / d) / fun( ) ) * 5),, C /*, * / ANSI C,, : / * this is / * an error * / * / Turbo C,, C,,,,,,, ;,, ( ),,,,,,,, C C C,, C, : int a = 3, x; x = a +++ a ++ ; :, a ++ 3, a 4, a ++ 4, a 5, x = 7, 6, a ++, a x = a a ++ ; y = x +++ x; y = a a; z = ++ a +++ a +++ a; x = a +++ a ++ ; : x = a ++ ; x = x + a ++ ; 30 int i = 3; printf( i = % d, i ++ = % d, ++ i = % d \ n, i, i ++, ++ i) ; :,, : i = 3, i ++ = 3, ++ i = 5, :
38 2 i = 5, i ++ = 4, ++ i = 4? PC,,,! C, : a&&b&&c a b c a 0, b c,, a b, a 0, b c,, a b,,,,, : ( a = 5 + 3) ++ b / * 1, a 8, b, 1 * / ( a = 5 + 3) && a > 0++ b / * 1, 1, b, 1 * / ( a = 5 + 3) && a < 0 && ++ b / * a < 0 0, 0, b, 1 * /, ( ),, ++ b, : ( a = 5 + 3) b, b 2. 1 : ( 1 ) x + y% 3* ( int) ( x + y) % 3 /7, x = 4. 2, y = 2. 5 ( 2 ) ( float) ( a + b) /5 + ( int) b% ( int) a, a = 3, b = 4 ( 3 ) a + = a, a - = 2, a* = 2 + 3, a = : ( 1 ) short a = e - 1; ( 2 ) double b = e2. 5 ; ( 3 ) long do = 0xfdaL; ( 4 ) float 2 and = 1 - e : ( 1) #include < stdio. h > { double d; float f; long l; int i; i = f = l = d = 20 / 3; printf( % d % ld % f % f\ n, i, l, f, d) ; ( 2) #include < stdio. h > { int i, j, m, n, s; i = 5; j = 10; m = ++ i; 31
39 C 32 n = j ++ ; s = m ++ - n; printf( i = % d \ tj = % d \ tm = % d \ tn = % d \ ts = % d \n, i, j, m, n, s) ; ( 3) #include < stdio. h > { char c1, c2; int i, j; c1 = a ; c2 = b ; printf( c1 = % c \t% d \ t% o\ t% x\ n, c1, c1, c1, c1) ; printf( c2 = % c \t% d \ t% o\ t% x\ n, c2, c2, c2, c2) ; ( 4) #include < stdio. h > { int x, y, z; x = y = z; z = 3; y = x ++- 1; printf( % d \t% d \ t, x, y) ; y = ++ x - 1; printf( % d \t% d \ n, x, y) ; y = z ; printf( % d \t% d \ t, z, y) ; y = - - z + 1; printf( % d \t% d \ n, z, y) ; 2. 4 ( 1) #include stdio. h ; { float r, s; printf( input the radius: \ n) ; scanf( % f, r) ; ( 2) #include stdio. h s = * r* r; printf( % f\ n, s) ; { int a, b, c, v; / * / * a, b, c are sides* /, / * v is volume of cube* /* / a = 2. 0; b = 3. 0; c = 4. 0 v = a* b* c; printf( % d \ n, v) ; 2. 5 :
40 2 C = 5 9 ( f - 32 ), : F 30, 60, 90, , 2. 8, a b, 2. 9, a, b, c,, 2. 10,, 3
41 3,,, C,, C 3. 1 C C C C 3 ( 1 ) C, : x = 0; /* * / i ++ ; /* * / printf( ) ; /* * /, ( 2 ), : 1 ), : : if else switch( ) : while while( ) 34
42 3 do do while( ) for for( ) 2 ), : continue switch break return goto ( 3 ),,,, ( 4 ) C, {,,, : if ( x < y) { int t; / * t * / t = x; / * t, x y * / x = y; y = t; x y,, :,,,, , 3, 1966, Bohm Jacopini 3, ,, ;,,,,, C, 3 C ; if switch; while, for do while 35
43 C 杂员 再 条件 晕 条件 晕 杂圆 杂员 杂圆 杂员 再 顺序结构选择结构循环结构 if ( 1 ) else if else if : if ( ) ;, else if 3. 2,,, if ;, if if,, : else if 3. 1,, #include < stdio. h > { int choice, value; printf (" Convert: \ n" ) ; / * * / printf (" 1: decimal to hexadecimal \ n " ) ; 36 0
44 3 printf( " 2: hexadecimal to decimal \ n " ) ; printf( " 3: decimal to octal \ n " ) ; printf( " 4: octal to decimal \ n" ) ; printf( " enter your choice: " ) ; scanf( " % d", &choice) ; / * * / if ( choice == 1) / * 1 * / { printf( " enter a decimal value: " ) ; scanf( " % d", &value) ; printf( " % d in hexadecimal is: % x\ n ", value, value) ; if ( choice == 2) / * 2 * / { printf( " enter a hexadecimal value: " ) ; scanf( " % x", &value) ; printf( " % x in decimal is: % d \ n ", value, value) ; if ( choice == 3) / * 3 * / { printf( " enter a decimal value: " ) ; scanf( " % d", &value) ; printf( " % d in octal is: % o\ n ", value, value) ; if ( choice == 4) / * 4 * / { printf( " enter a octal value: " ) ; scanf( " % o", &value) ; printf( " % o in decimal is: % d \ n ", value, value) ; : Convert: 1: decimal to hexadecimal 2: hexadecimal to decimal 3: decimal to octal 4: octal to decimal enter your choice: 3 enter a decimal value: 28 in octal is: 34 if,,, : if ( 2 ) else if else if, if : 37
45 C if ( ) 1; else 2; if 3. 3,,, if 1;, else, else 2 : if, else, if else, 3. 2, #include < stdio. h > { int x; printf( " enter a integer number: " ) ; / * * / scanf( " % d", &x) ; if ( x% 2 == 0) printf( " The number is even \ n " ) ; / * x 2, * / else printf( " The number is odd number \ n " ) ; / * x 2, * / , ( ) if #include < stdio. h > { int a, b; printf (" enter two number: " ) ; scanf (" % d% d", &a, &b) ; if( b) printf (" % f \ n", ( float) a /b) ; / * b 0, float * / else printf (" cannot divide by zero\ n" ) ; / * b 0, * /, if( b) if ( b! = 0) ( 3 ) if if if if, if if else if : if ( x) 38
46 3 if ( y) printf( " 1" ) ; else printf( " 2" ) ; if else? C : else else if,, else if ( y) else if( x), if : if ( x) { if ( y) printf( " 1" ) ; else printf( " 2" ) ; else if( x), if( y) if if_else_if, if_else_if, if,, if, if_else_if, if, 3. 4 #include < stdio. h > { int choice; int value; printf( " Convert: \ n" ) ; printf( " 1: decimal to hexadecimal \ n " ) ; printf( " 2: hexadecimal to decimal \ n " ) ; printf( " 3: decimal to octal \ n " ) ; printf( " 4: octal to decimal \ n" ) ; printf( " enter your choice: " ) ; scanf( " % d", &choice) ; if ( choice == 1) { printf( " enter decimal value: " ) ; scanf( " % d", &value) ; printf( " % d in hexadecimal is: % x\ n ", value, value) ; else if ( choice == 2) { printf( " enter hexadecimal value: " ) ; scanf( " % x", &value) ; printf( " % x in decimal is: % d \ n ", value, value) ; else if ( choice == 3) { printf( " enter decimal value: " ) ; scanf( " % d", &value) ; printf( " % d in octal is: % o\ n ", value, value) ; 39
47 C else if ( choice == 4) { printf( " enter octal value: " ) ; scanf( " % o", &value) ; printf( " % o in decimal is: % d \ n ", value, value) ; switch if_else_if,,, C, switch ( 1 ) switch switch : switch( ) { case 1: 1 case 2: 2 case n: default: n n + 1 switch, case,, case ; case,, switch, default n + 1 default, default,,,, 3 + 5, 4 * 8 switch n default n switch
48 3 switch : if : switch, if switch, case, switch, switch switch switch, switch if_else_if 3. 5 switch #include < stdio. h > { int choice; int value; printf( " Convert: \ n" ) ; /* * / printf( " 1: decimal to hexadecimal \ n " ) ; printf( " 2: hexadecimal to decimal \ n " ) ; printf( " 3: decimal to octal \ n " ) ; printf( " 4: octal to decimal \ n" ) ; printf( " enter your choice: " ) ; scanf( " % d", &choice) ; switch ( choice) { case 1: / * 1 * / printf( " enter decimal value: " ) ; scanf( " % d", &value) ; printf( " % d in hexadecimal is: % x\ n", value, value) ; break; case 2: / * 2 * / printf( " enter hexadecimal value: " ) ; scanf( " % x", &value) ; printf( " % x in decimal is: % d \ n", value, value) ; break; case 3: / * 3 * / printf( " enter decimal value: " ) ; scanf( " % d", &value) ; printf( " % d in octal is: % o \ n", value, value) ; break; case 4: / * 4 * / printf( " enter octal value: " ) ; scanf( " % o", &value) ; printf( " % o in decimal is: % d \ n", value, value) ; break; 41
49 C switch break, switch, switch ( 2 ) default switch default,, switch default : switch( ch) { case Y : case y : printf( " You answered YES! \ n" ) ; break; case N : case n : printf( " You answered NO! \n" ) ; break; switch,?,, default, : default: printf( " Unknown reponse: % d \n", ch) ;,, default default switch,, default, : default: printf( " invalid selection, try again \ n" ) ; ( 3 ) break 3. 5, break switch switch case,, break, switch switch, 1,..., n, n + 1 break, switch n default 2 n n break switch switch break, switch break, :,, break, break, break,, case break 42
50 3, switch, case, break : switch( country) { case China : case Japan : case India : printf( " Asia" ) ; break; case Britan : case France : case German : printf( " Europe" ) ; break; ( 4 ) switch switch switch, switch switch, switch case, : switch( x) { case 1: switch( y) { case 0: printf( " divide by zero error" ) ; break; case 2: break; case 1: process( x, y) ; break; 3. 6 ax 2 + bx + c = 0,, : b = 0 c = 0 a = 0 c0 b0 x = - c / b a0 d = b 2-4ac d0 d < 0 : #include < stdio. h > #include < math. h > 43
51 C { float a, b, c, d, x1, x2, real, imag; printf( " please input a, b, c = " ) ; / * 3 * / scanf( " % f, % f, % f", &a, &b, &c) ; if ( fabs( a) < = 1e - 6) / * a = 0 * / { if ( fabs( b) < = 1e - 6) printf( " error \ n" ) ; / * b = 0 * / else / * b0 * / printf( " The equation has a root: % 6. 2f \n", - c / b) ; else / * a0 * / { d = b* b - 4* a* c; if ( fabs( d) < = 1e - 6) / * d = 0 * / printf( " The equation has two equal roots: % 6. 2f \n", - b / ( 2* a) ) ; else if ( d > 1e - 6) / * d > 0 x1 x2 * / { x1 = ( - b + sqrt( d) ) / ( 2* a) ; x2 = ( - b - sqrt( d) ) / ( 2* a) ; printf( " distinct real roots: % 6. 2f and % 6. 2f \ n", x1, x2) ; else / * d < 0 * / { real = - b / ( 2* a) ; / * * / imag = sqrt( - d) / ( 2* a) ; / * * / printf (" The equation has complex roots: \n) ; / * a + bi * / printf (" % 6. 2f + % 6. 2fi \ n", real, imag) ; printf (" % 6. 2f - % 6. 2fi \ n", real, imag) ; if-else, if-else : ( ) 0, : if ( d == 0)... 0, 0 fabs ( d ) ( 1 e - 6),, d = y = : x ( 0x < 10) 5 x + 3 ( 10x < 20) 3 x - 11 ( 20x < 30) 2 x + 7 ( 30x < 40) 6 x ( x40 ),, 10 ( 0, 10, 20, 30), 10, : 44
52 3 x x / , switch #include < stdio. h > { int x, y, m; printf( " Please input x: " ) ; scanf( " % d", &x) ; if ( x > = 40) m = 4; else m = x /10; switch( m) { case 0: y = x; break; case 1: y = 5* x + 3; break; case 2: y = 3* x - 11; break; case 3: y = 2* x + 7; break; case 4: y = 6* x ; break; default: printf( " The input data is invalid. \ n" ) ; printf( " The result is % d \ n", y) ; 3. 3,,, C C for while do_while for :,, 50, 100,, for ( 1 ) for for : for( 1; 2; 3 ) ; 3,, for 1,, ; 2,, 2 45
53 C ; 3,,, 3 for #include < stdio. h > { int x; for( x = 1; x < = 100; x ++ ) printf( " % d ", x) ;, x 1x 100, printf( ) printf( ), x 1, x 1 00 x 1 0 0, for, x, x for x < = 100, x,, : #include < stdio. h > { int x; for( x = 100; x > 0; x - - ) printf( " % d", x) ;, for 0 99 : #include < stdio. h > { int i; for( i = 0; i < 100; i ++ ) { printf( " this is i: % d", i) ; printf( " and i square: % d \ n", i* i) ; for,, : x = 10; for ( y = 10; y! = x; ++ y) printf( " % d", y) ; printf( " % d", y) ;, x y,,, y 10,
54 3 ( 2 ) for for, 1 ) for,, x y : #include < stdio. h > { int x, y; for ( x = 0, y = 0; x + y < 100; ++ x, y ++ ) printf( " % d", x + y) ; 0 98, x y 1 2 ) for for, 2,, 3,, for 3,, 10: for ( x = 0; x! = 10; ) scanf( " % d", &x) ; 3 ) for, 3, : for ( ; ; ) printf( " this loop will run forever \ n" ) ;,, : for ( ; ; ) if ( scanf( " % d", &x) ) / *, * / printf( " if enter number then this loop will run forever \ n" ) ; else /*, scanf( ), 0, * / break; 4 ) for for, for : for ( t = 0; t < time; t ++ ) ; / * * /, time while ( 1 ) while while : while ( ) ; 47
55 C,,,, for, while,, while 3. 7,, A: wait( ) { char ch; ch = \0 ; / * ch * / while ( ch! = A ) ch = getchar( ) ; while, ch A, ch,,,, A, ch!, = A while, ch,, ch A while, while : while( ( ch = getchar( ) )! ( 2 ) while = A ) ; 3. 7 while, while, for, while?, while 3. 9 #include < stdio. h > { int count = 0; printf( " type in a phrase: \ n" ) ; while ( getchar( )! count ++ ; = \r ) / * * / printf( " \ ncharacter count is % d", count) ; : type in a phrase: cat character count is 3, while for?,,, 48 测试表达式 非园 循环体 憎澡蚤造藻语句的后继语句 0
56 3, while while : ( getchar( )! = \ r ) getchar( ),,,, \ r, \ r, while,, ( 3 ) while while, getchar( ), while ch getchar( ) : #include < stdio. h > { int count = - 1; char ch; printf( " type in a phrase: \ n" ) ; ch = getchar( ) ; while ( ch! = \ r ) { ch = getchar( ) ; count ++ ; printf( " \ ncharacter count is % d", count) ; while,?, ch ch, while, getchar( ) while, C while( 1 ) {,, : while( 1) { ch = getchar( ) ; printf( " \ nthe code for % c id % d. \ n", ch, ch) ;,, : if ( ) break; 非园 循环体 测试表达式 0 憎澡蚤造藻语句的后继语句 3. 8 do while 49
57 C do while ( 1 ) do while do{ ; while ( ) ;,, while do while do while 3. 8 do, do while do, ; while,, do while for while,,, ;, do while do while, 100 do{ scanf( " % d", &num) ; while( num > 100) ; ( 2 ) do_while do?,, do while while, while,, do while,, do while, do while : do{ printf( " convert: \ n" ) ; printf( " 1: decimal to hexadecimal \ n " ) ; printf( " 2: hexadecimal to decimal \ n " ) ; printf( " 3: decimal to octal \ n " ) ; printf( " 4: octal to decimal \ n" ) ; printf( " enter your choice: " ) ; scanf( " % d", &choice) ; while( choice < 1 choice > 4) ;,, 100 : { int count = 1; 50
58 3 int total = 0; do{ total + = count; count + = 2; while( count < 100) ; printf( " total = % d \ n", total) ; ( 1 ) while, a e : #include " stdio. h" #include " conio. h" / * clrscr( ) * / { char ch1, ch2; while ( ( ch1 = getchar( ) )! = EOF) / * ch1, ctrl + z * / { clrscr( ) ; / *, * / printf( " \ ntype in a letter from a to e : \ n" ) ; while ( ( ch2 = getchar( ) )! = ch1) / *, * / { printf( " \ nsorry, % c is incorrect. \ n", ch) ; / * * / printf( " \ ntry again. \ n" ) ; printf( " \ nthat s it! \ n" ) ; / *, * / while EOF( stdio. h ),, ;,,, ( 2 ) C,,, {,,, { Kernighan Ritchie, Allman, Whitesmiths 3 3 1) K&R C ( The C Programming Language), Brian Kernighan Dennis Ritchie, : 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; 51
59 C printf( " % c", c) ; K&R, {,, 2) Allman Allman : 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) ; Allman, {, { 3) Whitesmiths Whitesmiths : 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) ; Allman, Whitesmiths {,,, break continue ( 1 ) break break : break; break switch switch break switch, break,, s = n n
60 3 #include < stdio. h > { int i = 1, s = 0; while( 1) { s + = i* i; if ( s > 1000) / * s, s > 1000 * / break; printf( " n = % d \ n", i - 1) ;,, break ( 2 ) continue continue : continue; continue,, continue , 7 #include < stdio. h > { int s; for( s = 1; s < = 1000; s ++ ) if ( s% 3 == 0) / * 3 * / if( s% 7 == 0) / * 7 * / continue; / *, * / else /* 3, 7 * / printf( " % d ", s) ; continue break continue, break , { int num, c; printf( " input an integer: " ) ; / * * / scanf( " % d", &num) ; 0 测试表达式非园 continue 憎澡蚤造藻语句的后继语句 continue do { c = num% 10; / * 10,, num * / printf( " % d", c) ; / * * / 53
61 C while( ( num / = 10) > 0) ; / * num, 10 * / printf( " \ n" ) ; { int m, n, flag; /* flag, 1, 0 * / printf( " % d ", 2) ; /* 2 * / for( m = 3; m < = 1000; m ++ ) /* m * / { flag = 1; /* flag 1, m * / for( n = 2; n < m; n ++ ) /* n, 2 m - 1 * / if( m% n == 0) /* n m, * / { flag = 0; break; if( flag == 1) printf( " % d", m) ; / *, * / m, m : break n m, flag : ;, n, n sqrt( m) m - 1,, #include " math. h" / * sqrt( ) * / { int m, n, flag; /* flag, 1, 0 * / printf( " % d", 2) ; /* 2 * / for( m = 3; m < = 1000; m + = 2) /* m * / { flag = 1; /* flag 1, m * / for( n = 2; n < sqrt( m) ; n ++ ) / * n, 2 sqrt( m) * / if( m% n == 0) /* n m, * / { flag = 0; break; if( flag == 1) printf( " % d", m) ; / *, * / 3. 4 goto goto goto C,, goto, 1 100, goto : 54
62 3 x = 1; loop1: x ++ ; if ( x < 100) goto loop1; goto : for(... ) { for(... ) { while(... ) { if(... ) goto stop; stop: printf( " error in program. \ n) ; break,,, goto, goto goto,,, goto, goto,, goto , 81, 9 :, : 144( 12* 12) 676( 26* 26), #include < stdio. h > { int n, k, a, b, c; for ( k = 1; ; k ++ ) / * * / { n = k* k; if ( n < 100) continue; / * n, * / if ( n > 999) break; / * n, * / a = n / 100; / * a * / b = ( n - a* 100) /10; / * b * / c = n% 10; / * c * / if (! ( a - b) * ( a - c) * ( b - c) ) / * * / printf( " n = % d = % d* % d \ n", n, k, k) ; 55
63 C s = 1 - #include < stdio. h > { float s = 0. 0, w, f = ; int i; printf( " please input n: " ) ; scanf( " % d", &n) ; for ( i = 0; i < = n; i ++ ) { n - 1 f = ( ) * f; / * f * / w = f / ( 2* i + 1) ; / * w * / s + = w; printf( " the result is % d. ", s) ; : x sin( x) = 0 x0 = 1, 10-6 x n + 1 = x n - f( x n ) f ( x n ), x n + 1 f( x) = 0 f( x) = x sin( x), f ( x) = sin( x) + xcos( x) #include < stdio. h > #include < math. h > { float x1, x0 = 1, f, f1; do{ x1 = x0; /* * / f = x0* sin( x0) ; / * f( x) * / f1 = sin( x0) + x0* cos( x0) ; / * f ( x) * / x1 = x0 - f/ f1; / * * / while( fabs( x1 - x0) > 1e - 6) / * * / printf( " The result is % f6. 2. ", x1) ; 3. 1, 3. 2, 3. 3, 3. 4 : 56
64 , 3 2, 5 3, 7 2,? 3. 6 e = 1 1! + 1 2! n!, ,,, n, 57
65 4 C, C,, ( 1 ), : [ ] ;,, ;,, s name : int s[ 10] ; char name[ 50] ; ( 2 ),,?, : [ ], s[ 5] name[ 33] C, 0, s 9, 10, s[ 0 ] s [ 1 ] s [ 2 ]... s[ 9 ] name 49, 50, name[ 0 ] name[ 49] 58
66 4 :, ( 3 ), C,, s, s 4. 1 s[ 0] s[ 1] s[ 2] s[ 3] s[ 4] s[ 5] s[ 6] s[ 7] s[ 8] s[ 9] 4. 1 s ( 1 ) C,, : [ ] = { ;,,,,, : int s[ 10] = {0, 2, 4, 6, 8, 9, 7, 5, 3, 1 ; 4. 1, #include < stdio. h > #define LIM 5 int table[ LIM] = {50, 20, 10, 5, 1 ; /* table * / { int dex, amount, quantity; printf( " : " ) ; scanf( " % d", &amount) ; for ( dex = 0; dex < LIM; dex ++ ) { quantity = amount /table[ dex] ; printf( " = % 2d, ", table[ dex] ) ; printf( " = % 2d \ n", quantity) ; amount = amount% table[ dex] ; : : 138 = 50, = 2 = 20, = 1 = 10, = 1 = 5, = 1 = 1, = 3 59
67 C , 1, 1, 1 3 : 50 ( amount ), 50 ( ) ;, ( % ) amount, 20 5,, : int table[ LIM] = { 50, 20, 10, 5, 1 ; {,, table [ 0 ] 50, table[ 1 ] 20,, table[ 4] 1 ( 2 ) LIM ( #define 5) : int table[ LIM] = {50, 20, 10, 5, 1 ;,,?, 0 ; : int s[ 10] = {0, 2, 4, 6, 8; s[ 5] s[ 9] 0 : int table[ ] = {50, 20, 10, 5, 1; table? :,,,,, #include < stdio. h > #define N 20 / * 20 * / { int i, max, min, s[ N] ; for( i = 0; i < N; i ++ ) scanf( " % d", &s[ i] ) ; / * s * / max = min = s[ 0] ; / * 1 * / for( i = 1; i < N - 1; i ++ ) / *, * / if ( s[ i] > max) max = s[ i] ; else if ( s[ i] < min) min = s[ i] ; printf( " max = % d, min = % d \ n", max, min) ;
68 fabonacci 20 1, 2 : 1, 1, fabonacci : 1, 1, 2, 3, 5, 8, 13, 21, { int i; int f[ 20] = {1, 1 ; /* f, 1 * / for ( i = 2; i < 20; i ++ ) / * 3, * / f[ i] = f[ i - 1] + f[ i - 2] ; for ( i = 0; i < 20; i ++ ) / * * / { if( i% 5) printf( " \ n" ) ; / * 5 * / printf( " % 12d", f[ i] ) ;,, for, 1 1, ( 1 ) C,, \0 ( 0), 1, 10, : char str[ 11] ;,, \0, ( 2 ) 1 ),, : char s1[ 10] = { H, e, l, l, o, \0 ;, s
69 C S H e 1 1 o \0 \ 0 \0 \0 \0 : 2 ) 4. 2 s1 C,, char s1[ 6] = " Hello" ;, \ 0,,, : char s2[ ] = " This is a string" ; s ,?, scanf( ), : { char name[ 15] ; printf( " Enter your name: " ) ; scanf( " % s", name) ; printf( " Greetings, % s. \ n", name) ; : Enter your name: Mary Greetings, Mary. scanf( ) name \0 : for ( i = 0; i < 5; i ++ ) scanf( " % c", &name[ i] ) ; : name[ 0] = M ; name[ 1] = a ; name[ 2] = r ; name[ 3] = y ; name[ 4] = \ 0 ;, : name = Mary ;, name,, : char name[ 15] = Mary, name1[ 15] ; name1 = name; C,
70 4 ( 1 ) gets( ) gets( ) : gets( ) ;, gets( ),, gets( ) stdio. h, #include < stdio. h > { char str[ 80] ; printf( " enter a string: " ) ; gets( str) ; printf( " % s \ n", str) ; str printf( ), : gets( ),,, gets( ), ( 2 ) C : strcpy ( ) strcat( ) strlen( ) strcmp ( ), : string. h 1 ) strcpy( ) strcpy( ) : strcpy( to, from) strcpy( ) from to to from, hellostr : #include < stdio. h > #include < string. h > { char str[ 80] ; strcpy( str, " hello" ) ; printf( " % s", str) ; 2 ) strcat( ) strcat( ) : 63
71 C strcat( s1, s2) ; strcat( ) s2 s1, s2, hello there : #include < stdio. h > #include < string. h > { char s1[ 20], s2[ 10] ; strcpy( s1, " hello" ) ; strcpy( s2, " there" ) ; strcat( s1, s2) ; printf( " % s", s1) ;, s1, s1 s2, 3 ) strlen( ) strlen( ) : strlen( s) ; s strlen( s) s : #include < stdio. h > #include < string. h > { char str[ 80] ; printf( " enter a string: " ) ; gets( str) ; printf( " % d", strlen( str) ) ;, hi, there, 8 strlen( ) 4 ) strcmp( ) strcmp( ) : strcmp( s1, s2) ; strcmp( ), 0, s1 s2, ; s1 s2, flag , { char s[ 80], password[ ] = A123 ; / * password * / int flag = 0, n = 3; / * flag, 0, n * / do{ printf( " enter password: " ) ;
72 4 gets( s) ; / * * / if (! ( strcmp( s, password) ) / * * / { printf( " OK! \ n" ) ; flag = 1; / * flag 1 * / break; / * * / else if( n > 0) / * * / { printf( " password error, input again! \ n" ) ; while( n > 0) ; if(! flag) n - - ; / * * / { printf( " sorry, you is nt valid user, goodbye! \ n" ) , binary, #include < stdio. h > #include < math. h > #define M 16 { char ch, binary[ M] ; int i, j, dec, ndec, index = 0; / * index binary * / printf( " : " ) ; scanf( " % d", &dec) ; ndec = abs( dec) ; / * dec * / while( dec) { str[ index ++ ] = dec% ; / * * / dec / = 2; binary[ index - - ] = \0 ; / *, index \0 * / for ( i = 0, j = index; i < j; i ++, j - - ) /* * / { ch = binary[ i] ; binary[ i] = binary[ j] ; binary[ j] = ch; printf( " % d : % s \ n", dec, str) ; : : , ( ) 65
73 C #include < stdio. h > main ( ) { int c, i, nwhite, nother, ndigit[ 10] ; / * : nwhite, ndigit[ 10] ndigit[ 0] ndigit[ 9] 0 9, nother* / nwhite = nother = 0; / * 0 * / for ( i = 0; i < 10; ++ i) ndigit[ i] = 0; while( ( c = getchar( ) )! { switch( c) = EOF) { case 0 : case 1 : case 2 : case 3 : case 4 : case 5 : case 6 : case 7 : case 8 : case 9 : ++ ndigit[ c - 0 ] ; / * * / break; case : case \ n : case \ t : ++ nwhite; / * * / break; default: printf( " digits = " ) ; ++ nother; / * * / break for ( i = 0; i < 10; ++ i) printf( " % d", ndigit[ i] ) ; printf( ", white space = % d, other = % d \n", nwhite, nother) ;, int ndigit[ 10] 10 ndigit : if ( c > = 0&& c < = 9 ) c, : c - ndigit 0, 4. 3 C,, :
74 4 [ 1] [ 2] ; [ 1] [ 2] = { ;, 1, 2, a 34( 3 4 ) int : int a[ 3] [ 4] ; 0, a 2, 3,,, ( a ) : a[ 0 ] [ 0 ] a [ 0 ] [ 1 ] a [ 0 ] [ 2 ] a [ 0 ] [ 3 ] a [ 1 ] [ 0 ] a [ 1 ] [ 1 ] a [ 1 ] [ 2 ] a[ 1 ] [ 3 ] a[ 2] [ 0] a[ 2] [ 1] a[ 2] [ 2] a[ 2] [ 3 ], ( ) ( ) a [ 3 ] [ 4] 3 a[ 0] a [ 1 ] a [ 2 ], a [ 0] a[ 1] a[ 2 ] 3 a[ 0 ] 4, a[ 0] [ 0] a[ 0] [ 1 ] a[ 0] [ 2] a[ 0] [ 3] a[ 1] 4, a[ 1] [ 0] a[ 1] [ 1 ] a[ 1] [ 2] a[ 1] [ 3], a[ 2] 4, a[ 2 ] [ 0 ] a[ 2 ] [ 1 ] a[ 2] [ 2] a[ 2] [ 3], : int a[ 3] [ 4] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ; : : int a[ ] [ 4] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ; 2 : int a[ 3] [ 4] = { {1, 2, 3, 4, {5, 6, 7, 8, {9, 10, 11, 12 ; int a[ ] [ 4] = { {1, 2, 3, 4, {5, 6, 7, 8, {9, 10, 11, 12 ;, : int a[ ] [ 4] = {{1, 2, {, {0, 10, 11, 12 ; : : 67
75 C [ 1] [ 2] 1, #include < stdio. h > #define M 5 #define N 4 { int i, j, data[ M] [ N] ; for ( i = 0; i < M; i ++ ) / *, i, j * / for ( j = 0; j < N; j ++ ) scanf( " % d", &data[ i] [ j] ) ; for ( i = 0; i < M; i ++ ) / *, i, j * / { for ( j = 0; j < N; j ++ ) printf( " % 8d", &data[ i] [ j] ) ; printf( " \ n" ) ; / * * /,,,, : a[ 1] [ 2] = 3; a[ 2] [ 3] = a[ 1] [ 2] + 5; , : , 61 { char daytab[ 2] [ 13] = { { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, / * * / { 0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 ; / * * / int year, month, day; int i, leap, dayth; /* dayth * / printf( " - - : " ) ; scanf( " % d - % d - % d", &year, &month, &day) ; leap = year% 4 == 0 && year% 100! = 0 year% 400 == 0; / * leap * / dayth = day; for( i = 1; i < month; i ++ ) dayth + = daytab[ leap] [ i] ; printf( " % d % d % d % d ", year, month, day, dayth) ;? daytab
76 4 leap : leap = year% 4 == 0&&year% 100! = 0 year% 400 == 0; 4 100, 400, 1900, 2000 leap 0( ) 1( ), daytab :? 4. 4 C : [ 1] [ 2] [ N] ; [ 1] [ 2] [ N] = { ;, t 223 float : float t[ 2] [ 2] [ 3] ;, 3, 2, 1, : t[ 0] [ 0] [ 0] t[ 0] [ 0] [ 1] t[ 0] [ 0] [ 2] t[ 0] [ 1] [ 0] t[ 0] [ 1] [ 1] t[ 0] [ 1] [ 2] t[ 1] [ 0] [ 0] t[ 1] [ 0] [ 1] t[ 1] [ 0] [ 2] t[ 1] [ 1] [ 0] t[ 1] [ 1] [ 1] t[ 1] [ 1] [ 2], t[ 2] [ 2] [ 3] 22 t[ 0] [ 0] t[ 0] [ 1] t[ 1] [ 0] t[ 1 ] [ 1], 3 2 t[ 0] t[ 1], 2 3,,,, : = 2 160, 4 320, ( 8 ), , 4. 5 C,,,, N, N,, C,, (,! ) { int crash[ 10] ; for ( i = 0; i < 100; i ++ ) crash[ i] = i; 69
77 C, crash 10, 20, 100, 200,,, C?, C, ,,, :, ( ),, ;,,, N N - 1, #include < stdio. h > #define N 20 / * 20 * / { int i, j; int s[ N], t; for( i = 0; i < N; i ++ ) scanf( " % d", &s[ i] ) ; / * s * / for( i = 0; i < N - 1; i ++ ) / *, N - 1 * / for( j = 0; j < N - i - 1; j ++ ) / * * / if ( s[ j] > s[ j + 1] ) / *, * / { t = s[ j] ; s[ j] = s[ j + 1] ; s[ j + 1] = t; for( i = 0; i < N; i ++ ) / * * / printf( " % 10d", s[ i] ) ; ,, 505 mark 50, 50 average 50 : #include < stdio. h > #define M 50 #define N 5 { int mark[ M, N], i, j; float average[ N], t; printf( " : \ n" ) ; printf( " \n" ) ; for( i = 0; i < M; i ++ ) 70
78 4 for( j = 0; j < N; j ++ ) scanf( " % d", &mark[ i] [ j] ) ; for( i = 0; i < M; i ++ ) /* * / { t = 0; /* t * / for( j = 0; j < N; j ++ ) t + = mark[ i] [ j] ; average[ i] = t / N; printf( " \ n" ) ; printf( " " ) ; printf( " " ) ; for( i = 0; i < M; i ++ ) /* * / { for( j = 0; j < N; j ++ ) printf( " % 6d", mark[ i] [ j] ) ; printf( " % 12. 1f\ n", average[ i] ) ; printf( " " ) ; : : : 2, 2 2,, 3 3 3, 5,, 50 :, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,, 97, 98, 99, 100,, 5, 7, 9, 11,, 97, 99,,, 7, 11,, 97 #include < stdio. h > #define M
79 C { int i, p, flag, new, s[ M] ; for( i = 2; i < = M; i ++ ) s[ i] = i; / * s * / p = 0; do{ flag = 0; / * flag, 1 * / while (! flag) / * * / { if ( s[ p]! = - 1) / *,, * / { new = s[ p] ; flag = 1; else p ++ ; / * s[ p] - 1,, * / for( i = p + 1; i < = M; i ++ ) / * new * / if ( ( s[ i]! = - 1) &&( s[ i] % new == 0) ) s[ i] = - 1; while( new < = M/2) ; for( i = 2; i < = M; i ++ ) /* * / if ( s[ i]! = - 1) printf( " % 4d", s[ i] ) ; ( 1) #include < stdio. h > { int a[ 10], i, k = 0; for( i = 0; i < 10; i ++ ) a[ i] = i; for( i = 0; i < 10; i ++ ) k + = a[ i] + i; printf( " % d \ n", k) ; ( 2) #include < stdio. h > { int i, j, row, col, m; int a[ 3] [ 3] == {{1, - 2, 3, {27, 36, 45, { - 56, 47, 89 ; m = a[ 0] [ 0] ; for( i = 0; i < 3; i ++ ) for( j = 0; j < 3; j ++ ) if ( a[ i] [ j] < m) { m = a[ i] [ j] ; row = i; col = j;
80 4 printf( " % d, % d, % d \ n", m, row, col) ; 4. 2, : AZ BY CX az by cx 1 26, i ( 26 - i + 1), 4. 3, s2 s1 strcpy, \0, \0 : 4. 4,, space space paces acesp cespa espac 4. 5, string position, character abcdefgh 5 D, abcddefgh 4. 6 strcmp,,, ASCII : abcdefg abceef, , 4. 8, 4. 9 A + B AB a, 3
81 5 C C,,, C,, C ( 1 ),,,,,, short a , a 2010 a, a a, 5. 1 C,,, pa, a, pa = &a; &, &a a a &a: 2010 a, a, a ; pa, a, apa a a 74
82 5 pa pa = &a a, pa a, a pa pa * pa, *,, 5. 2,, a 2010, a 2010,, pa s a pa ( 2 ) & * 5. 2 & *, &, : &, &a &b[ 2] *, : * pa, &( * px) px, px * ( &x) x, x, & * &a a * pa pa a 5. 3 y = x px = &x; y = * px y = x; px = &x; y = * px; 5. 4 pa = &a * pa = a, x y,,, 5. 3 px = &z, y = * px, y z x pa = &a * pa = a, pa a, a pa, * pa a; pa a, a * pa, ( 5. 5) : px, * pxpx, &pxpx &px 5. 5 px * px px * px &px 75
83 C ( 3 ),,,, ,,, ( 1 ) : * ; : int * pc; / * pc int * / float * pa; / * pa float * / char * name; / * name char * /, : int * pc, * pd, a1, a2; float * pa, d; char * name, * addr, str[ 80] ;, C *, * *,,,,,,,, C, int pc char name, int char ( 2 ), : : : * = ; int * pa = &a, * px = &x; / * pa px, int a x * / float * s = &ss; / * s, float ss * /,, : 76 int n; int * p = &n; :
84 5 int n, * p = &n;, : float x, * p = &x, * q = p;, q p, x, : int * p = 0; int * p = NULL; NULL 0 stdio. h NULL : #define NULL ,,, : &, : int a, * pa; pa = &a; / * pa a * /, : char c, * s1 = &c, * s2; s2 = s1; / * s1 s2 c * /, : char * str, ch[ 80] ; str = ch; / * str ch, str ch * /,, int * p1, * p2, a[ 20] ; p1 = a; p2 = p1 + 5; p1 = p2-3; p1 + = 2; p2 - = 10; int * c, a = 20, * b = &a; float * p; : b = 2000; / * * / p = b; / * * / c = * b; c = a; / * * / 5. 1 a b, #include " stdio. h" 77
85 C {int a, b, * t, * a1 = &a, * a2 = &b; / * a1 a2, a1 a, a2 b * / scanf( " % d, % d", &a, &b) ; if ( a > b) / * a > b a1, a2 * / { t = a1; a1 = a2; a2 = t; / * a1 a2, a1 b, a2 a * / printf( " a = % d, b = % d \ n", a, b) ; printf( " min = % d, max = % d \ n", * a1, * a2) ; : 6, 3 a = 6, b = 3 min = 3, max = , a b, a1 a2, a1, a2,, 5. 6,,,, p : int * p, a = 5; /* p, p, p * / * p = a; /* p, * / pa pb ( ), n, : pa + n, pa - n, pa + +, + + pa, pa - -, - - pa, pa - pb ( 1 ) n, n,, pa short, px long, pa = pa + 1, pa 2; px = px + 1, px 4, p, p n : p ( n ) 78
86 5, p n, C,,, 5. 7, pa a pa a[ i], pa n a[ i] n, * ( pa n) ( 2 ) (! ) pa - 4 pa - 3 pa - 2 pa - 1 pa pa + 1 pa + 2 pa + 3 pa + 4 a[ i - 4] a[ i - 3] a[ i - 2] a[ i - 1] a[ i] a[ i + 1] a[ i + 2] a[ i + 3] a[ i + 4] * ( pa - 4) * ( pa - 3) * ( pa - 2) * ( pa - 1) * pa * ( pa + 1) * ( pa + 2) * ( pa + 3) * ( pa + 4) 5. 7 pa n a,,, int pa, pa n int a a : pa = a; / * pa a * / for( i = 0; i < n; i + + ) { printf( " a[ % d] = % d \ n", i, * pa) ; / * pa * / pa + + ; / * pa * /,, 4 ( y pa ) y = * pa + + ;,, : y = * ( pa + + ), pa, y, pa y = * + + pa; y = * ( + + pa),, pa, pa ( ), y y = ( * pa) + + ;, pa, y, pa y = + + * pa; y = + + ( * pa),, pa,,, y 79
87 C 5. 2 #include " stdio. h" s r {char s[ ] = " Good morning! " char r[ 20], * st, * rt; st = s; rt = r; / * st rt s r * / while ( ( * rt + + = * st + + )! printf( " s string is % s \ n", s) ; printf( " r string is % s\ n", r) ; : s string is Good morning! r string is Good morning! = \0 ) ;, ( * rt + + = * st + + )! = \0 : st rt, \0 st rt,,, st rt s r,, st rt,, \0, while ( ( * rt + + = * st + + )! = \0 ) ; while ( * rt + + = * st + + ) ;, : ( * rt = * st)!? ( 3 ) C,,,,, 5. 8, p q a p q a[ 2 ] a[ 9 ], q - p 7, p - q #include " stdio. h" {char str[ 30], * s; s = str; / * s str * / printf( " Enter a string( less than 30 characters) : \ n" ) ; scanf( " % s", str) ; / * * / while ( * s! = \ 0 ) s + + ; / * s * / printf( " The string length is % d \n", s - str) ; : Enter a string( less than 30 characters) : p q 5. 8 = \0, a[ 2] a[ 3] a[ 4] a[ 5] a[ 6] a[ 7] a[ 8] a[ 9] a
88 5 WINDOWS2000 The string length is 11, s \0 : while ( * s + +! = \0 ) ; while ( * s + + ) ;,,, s?,? , p q, p > q, p q ( ), p = = q 1, p q, p < q, p q p, p = = 0 p! = 0, p = = NULL p! = NULL 5. 3,,, ( 1 ), int a pa, : int a[ 20], * pa; : pa = a; pa = &a[ 0] ; a, a[ 0], pa * pa a[ 0] : int a[ 20], * pa = a;, a[ 5] : pa = &a[ 5] ; * pa a[ 5] ( 2 ),, 3 : 81
89 C, a[ i],, C, a + i a i a[ i], * ( a + i) a[ i], A. pa = a, pa + i pa i a[ i], * ( pa + i) a[ i] B. pa = a, * ( pa + i) a[ i], C pa[ i] pa i, pa a, pa = a ( pa a ), a[ i] : 5. 4 a[ i] * ( a + i) * ( pa + i) pa[ i] #include " stdio. h" {int * p, num[ 4], i; p = num; / * * / for ( i = 0; i < 4; i + + ) * ( p + i) = i + 1; / * * / for ( i = 0; i < 4; i + + ) printf( " num[ % d] = % d \ t", i, num[ i] ) ; / * * / printf( " \ n" ) ; : 82 num[ 0] = 1 num[ 1] = 2 num[ 2] = 3 num[ 3] = #include " stdio. h" 10, data, 10 {float * p, * pend, data[ 10], max, min; * p = * pend = data; / * * / printf( " Enter 10 number: \ n" ) ; for ( i = 0; i < 10; i + + ) scanf(% f, pend ++ ) ; / * pend + +, * / / *, pend data[ 9] * / max = min = * data; / * data[ 0] * / for ( p = data + 1; p < pend; p + + ) / *, p data[ 1] data[ 9] * / if ( * p > max) max = * p; else if ( * p < min) min = * p; printf( " max = % f\ tmin = % f\ n", max, min) ;
90 5 : Enter 10 number: max = min = ,,?,, ;,,,, a p b, a = p a = &b a + + a a- - a a + = n a,, ( 3 ) C,, C, : #include " stdio. h" { char str[ ] = { A, B, C, D, * pc = str, int x = 3191; /* x = 0xc77 * / long y = ; / * y = 0x2412a0 * / printf( " pc[ % d] = % c \ n", 3, * ( pc + 3) ) ; printf( " pc[ % d] = % c \ n", 4, * ( pc + 4) ) ; printf( " pc[ % d] = % c \ n", 8, * ( pc + 8) ) ; 5. 9, str, 4, x ( 2 short ) y ( 4 long ), : pc[ 3] = D pc[ 4] = w pc[ 8] =,,,,,,, pc + 0 str pc + 1 pc + 2 pc + 3 pc + 4 x pc + 5 pc + 6 y pc + 7 pc + 8 pc a,, 5. 10,, a a[ 3 ], a;, a[ 0 ] a[ 1] a[ 2 ],, a[ 0 ] a [ 1 ] a [ 2 ], 83
91 C 4, a a &a[ 0] a [ 0 ] &a [ 0] [ 0 ],, a, &a[ 0 ] a[ 0 ] a[ 0], &a[ 0] [ 0] a[ 0] a[ 1] a[ 2], a[ 0] &a[ 0] [ 0], a[ 1] &a[ 1] [ 0], a[ 2 ] &a[ 2] [ 0], +, : : a[ 0 ] * ( a + 0 ) * a ; a[ i] * ( a + i) ; : ; ;, ; &a[ 1] [ 3] a [ 1 ] + 3 * ( a + 1) + 3 &a[ 2] [ 1] a [ 2 ] + 1 * ( a + 2) + 1 &a[ i] [ j] a[ i] + j * ( a + i) + j, a[ i] [ j] * ( a[ i] + j), * ( * ( a + i) + j) ; i = 0, 1, 2; j = 0, 1, 2, 3, a [ i] * ( a + i), 5. 6 #include " stdio. h" { int a[ 3] [ 4] = {1, 2, 3, 4, 11, 12, 13, 14, 21, 22, 23, 24 ; int i, j; for ( i = 0; i < 3; i + + ) { for( j = 0; j < 4; j + + ) : a[ 0] a[ 1] a[ 2] printf( " % 4d", * ( * ( a + i) + j) ) ; / * a[ i] [ j] * / printf( " \n" ) ; * ( * ( a + i) + j) a[ i] [ j] a a[ 0] [ 0] a[ 0] [ 1] a[ 0] [ 2] a[ 0] [ 3] a[ 1] [ 0] a[ 1] [ 1] a[ 1] [ 2] a[ 1] [ 3] a[ 2] [ 0] a[ 2] [ 1] a[ 2] [ 2] a[ 2] [ 3] a[ 0 ] + 0 a[ 0 ] + 0 a[ 0 ] + 1 a[ 0 ] + 1 a[ 0 ] + 2 a[ 0 ] + 2 a[ 0 ] + 3 a[ 0 ] + 3 a[ 1 ] + 0 a[ 0 ] + 4 a[ 1 ] + 1 a[ 0 ] + 5 a[ 1 ] + 2 a[ 0 ] + 6 a[ 1 ] + 3 a[ 0 ] + 7 a[ 2 ] + 0 a[ 0 ] + 8 a[ 2 ] + 1 a[ 0 ] + 9 a[ 2 ] + 2 a[ 0] + 10 a[ 2 ] + 3 a[ 0] + 11 a, ( ), &a[ 1 ] [ 1] a[ 0 ] + 5 &a[ 0] [ 0] + 5, a + 5, 84
92 5, * ( a + 5) a[ 5], 5. 7 #include " stdio. h" { int a[ 3] [ 4] = {1, 2, 3, 4, 11, 12, 13, 14, 21, 22, 23, 24 ; int * p; p = a[ 0] ; while( p < a[ 0] + 12) printf( ( i% 4)? " % 4d" : " \ n% 4d", * p ++ ) ; 5. 6,,, * p + +, p = a[ 0 ] ; p = a;??,, * ( a[ i] + j) * ( * ( a + i) + j) a[ i] [ j] p, ( * p) [ i] 5. 8 #include " stdio. h" { int a[ 3] [ 4] = {1, 2, 3, 4, 11, 12, 13, 14, 21, 22, 23, 24 ; int ( * p) [ 4], i, j; / * p 4 * / p = a; / * p * / printf( " Enter i, j: " ) ; scanf( " % d, % d", &i, &j) ; printf( " a[ % d, % d] = % d \ n", i, j, ( * p + i) [ j] ) ; : Enter i, j: 2, 3 a[ 2, 3] = 24 t[ 3] [ 4] [ 5], t[ 0] t[ 1] t[ 2 ], 4, 5 ;, t [ 0] t[ 0] [ 0] t[ 0] [ 1] t[ 0] [ 2] t[ 0] [ 3], t[ i] [ j] * ( t[ i] + j), t[ i] [ j] [ k] * ( * ( t[ i] + j) + k) * ( * ( * ( t + i) + j) + k), i = 0, 1, 2; j = 0, 1, 2, 3; k = 0, 1, 2, 3, char, C,, 85
93 C ( 1 ) \0, 5. 9 #include " stdio. h" { char s[ ] = " Good morning! " ; char * p; p = s; /* p s * / printf( " s string is % s\ n", s) ; printf( " ( 1) p string is % s \ n", p) ; p = s + 5; /* p s 5 m * / printf( " ( 2) p string is % s \ n", p) ; : s string is Good morning! ( 1) p string is Good morning! ( 2) p string is morning! % s p s, s ; p s, ( 2 ), : char * str = " I am a student. " ;,, ( 3 ) : char * str; str = " I am a student. " ;,, : char s[ 80] ; s = " I am a student. " ;, str = " I am a student. " ;, 86
94 #include " stdio. h" { char ch, * pc = " C language program. ", * p; printf( " Enter a character: " ) ; scanf( " % c", &ch) ; /* * / p = pc; /* p * / while( * p! = \0&& * p! = ch) /* p * / p + + ; /* p * / if ( * p = = ch) /*,, p * / else printf( " The character % c is % d-th \ n", ch, p-pc + 1) ; printf( " The character not found \ n" ) ; : Enter a character: e The character e is 10-th : Enter a character: s The character not fount #include " stdio. h" #include " string. h" /* ( 1 ) * /, { char str[ 80], * p, * q, t; printf( " Enter a string: " ) ; scanf( " % s", str) ; / * * / for( p = str, q = p + strlen( str) -1; p < q; p + +, q - - ) { t = * p; /*,, p \0 * / / * p, q \ 0,, p q, p, q, p > = q * / * p = * q; * q = t; printf( " The reversed string is: % s \ n", str) ; : Enter a string: abcdefgh / * * /
95 C The reversed string is: hgfedcba strlen( str), str string. h ,, : * [ ] ;,,, p, 3, int : int * p[ 3] ;, : float * px[ 5], * py[ 3], data[ 5] [ 10], a, b, * pa = &a; : int b[ 3] [ 4], * pb[ 3] ; b[ 3] [ 4] b[ 0 ] b[ 1 ] b [ 2] 3, 3 3 : 88 pb[ 0] = b[ 0] ; pb[ 1] = b[ 1] ; pb[ 2] = b[ 2] ; pb #include " stdio. h" { int b[ 3] [ 4], * pb[ 3], i, j; for( i = 0; i < 3; i + + ) / * * / for( j = 0; j < 4; j + + ) b[ i] [ j] = ( i + 1) * ( j + 1) ; pb[ 0] = b[ 0] ; / * 3 * / pb[ 1] = b[ 1] ; pb[ 2] = b[ 2] ; for( i = 0; i < 3; i + + ) / * * / { for( j = 0; j < 4; j + + ) printf( " b[ % d] [ % d] = % d ", i, j, * ( pb[ i] + j) ) ; printf( " \n" ) ;
96 5 : b[ 0] [ 0] = 1 b[ 0] [ 1] = 2 b[ 0] [ 2] = 3 b[ 0] [ 3] = 4 b[ 1] [ 0] = 2 b[ 1] [ 1] = 4 b[ 1] [ 2] = 6 b[ 1] [ 3] = 8 b[ 2] [ 0] = 3 b[ 2] [ 1] = 6 b[ 2] [ 2] = 9 b[ 2] [ 3] = ,, pb = b b[ i] [ j] * ( b[ i] + j) * ( pb[ i] + j) pb[ i] [ j] ,,, 5, : char name[ 5] [ 20] = { " Li Zhi", " Zhang Ji", " Jin Xi", " Wang Fei", " Liu Yi" ; : char * pname[ 5] = { " Li Zhi", " Zhang Ji", " Jin Xi", " Wang Xiaofang", " Liu Yi" ;,,,,,,,, ,,, #include " stdio. h" #include " string. h" { int i; char * pname[ 5] = { " Li Zhi", " Zhang Ji", 89
97 C " Jin Xi", " Wang Xiaofang", " Liu Yi" ; / * * / char name[ 20] ; printf( " Enter a name: " ) ; / * * / gets( name) ; for( i = 0; i < 5; i + + ) / * * / if ( strcmp( pname[ i], name) = = 0) / * * / break; if ( i < 5) / * i < 5, * / printf( " % s is No. % d student. \ n", pname[ i], i + 1) ; else printf( " % s is not in this class. \ n", name) ; : Enter a name: Zhang Ji Zhang Ji is No. 2 student. : Enter a name: Zang Ji Zhang Ji is not in this class. scanf, gets #include " stdio. h" #include " string. h" { int i; char * pstr[ 3] = { " Visual C ++ ", " C Programming", " C Language" ; char * temp; if ( strcmp( pstr[ 0], pstr[ 1] ) > 0) / * pstr[ 0] pstr[ 1] * / { temp = pstr[ 0] ; pstr[ 0] = pstr[ 1] ; pstr[ 1] = temp; / * pstr[ 0] pstr[ 1], pstr[ 0] pstr[ 1], pstr[ 1] pstr[ 0],,, * / if ( strcmp( pstr[ 0], pstr[ 2] ) > 0) { temp = pstr[ 0] ; pstr[ 0] = pstr[ 2] ; pstr[ 2] = temp; if ( strcmp( pstr[ 1], pstr[ 2] ) > 0) { temp = pstr[ 1] ; 90
98 5 pstr[ 1] = pstr[ 2] ; pstr[ 2] = temp; for( i = 0; i < 3; i + + ) printf( " % s \n", pstr[ i] ) ; : C Language C Programming Visual C , pa a, ppa pa, ppa,, * ppa pa, * * ppa = * ( * ppa) = * pa a, 5. 12, pname, * pname pname[ 0], * pname[ 0] * * pname pname[ 0 ] L ppa pa a &pa &a &pa * ppa * pa, * * ppa : ppa a * * ;,, : int a, * pa, * * ppa; char * pname[ 3], * * ppname = pname; #include " stdio. h" { int i; char * name[ ] = { " WINDOWS", " MS-DOS", " UNIX", " LINUX" ; char * * pp; for( i = 0; i < 4; i + + ) { pp = name + i; / * pp name[ i], pp = &name[ i] * / printf( " % s \ n", * pp) ; 91
99 C : WINDOWS MS-DOS UNIX LINUX : { char * name[ ] = {" WINDOWS", char while( * * pp! * * pp = name; = \0 ) " MS-DOS", " UNIX", " LINUX", " " ; printf( " % s \ n", * pp + + ) ;, pp name[ 0 ] name[ 4], * * pp, \ 0, ( ),,,,,, #include " stdio. h" char * a[ ] = { " gain", " much", " stronger", " point" ; char * * aa[ ] = { a + 2, a, a + 3, a + 1 ; char * * * aaa = aa; { printf( " % s", * aaa[ 2] ) ; / * * ( * ( aaa + 2) ) * aa[ 2] a + 3 " point" * / printf( " % s", * * aaa + 6) ; / * * aa[ 0] + 6a + 2 " stronger" 6 " er" * / printf( " % s", * + + * + + aaa + 2) ; / * * ( aa [ 1] + 1) + 2* ( a + 1) + 2a[ 1] " printf( " % s", aaa[ 0] [ - 1] + 1) ; much" 2 " ch", aaa aa [ 1], aa[ 1] a + 1 * / / * * ( aa[ 1] - 1) + 1* a + 1a[ 0] gain 92
100 5 1 " ain" * / : pointer chain main :,, copy file1. txt file2. txt, : 1 2 < >, copy,, file1 file2,, C,, C? C main,, C main main : main( int argc, char * argv[ ] ) { argc int, argv, C exefile 3, : exefile proc1. c proc2. c proc3. c, argc 4, argv 4, : argv[ 0] = " exefile" ; argv[ 1] = " proc1. c" ; 93
101 C argv[ 2] = " proc2. c" ; argv[ 3] = " proc3. c" ; main, argc argv,, int, char #include " stdio. h" main( int argc, char * argv[ ] ) { int i; printf( " argc = % d \ n", argc) ; printf( " Command name: % s \n", argv[ 0] ) ; for( i = 1; i < argc; i ++ ) printf( " Argument No. % d: % s \ n", i, argv[ i] ) ; cprog. exe, : cprog book pen paper / s : argc = 5 Command name : cprog Argument No. 1: book Argument No. 2: pen Argument No. 3: paper Argument No. 4: / s #include " stdio. h" s1 s2, s2 s1, { char s1[ 80], s2[ 80], * p1, * p2; int i; printf( " ( 40) : " ) ; gets( s1) ; printf( " ( 40) : " ) ; gets( s2) ; p1 = s1; / * p1 p2 s1 s2 * / p2 = s2; while( * p1! p1 + + ; = \0 ) / * p1 s1 \0* / while( ( * p1 + + = * p2 + + )! = \0 ) ; / * p2 p1 * / * p1 = \0 ; / * * /
102 5 : printf( " : % s \ n", s1) ; : abcde : fghijklm : abcdefghijklm strcat( s1, s2) #include " stdio. h" { char ch1, ch2, * pc = " C language program. ", * p; int flag; printf( " : % s\ n", pc" ) ; printf( " : " ) ; scanf( " % c", &ch1) ; printf( " : " ) ; scanf( " % c", &ch2) ; flag = 0; / * * / p = pc; / * p * / while( * p! = \0 ) / * p * / { if( * p = = ch1) / * ch1 ch2, * / { * p = ch2; flag = 1; p ++ ; / * p * / if ( flag = = 0) / * * / else : printf( " \ n" ) ; printf( " : % s \ n", pc) ; : C language program. : a : o : C longuoge progrom #include " stdio. h" #define N 5 ( ) { char * name[ ] = { " Li jun", " Wang xiaogang", " Che hong", 95
103 C " Shun dasheng", " Zhang zhigang" ; char * temp; int i, j, k; printf( " : \ n" ) ; for( i = 0; i < N; i + + ) / * * / puts( name[ i] ) ; for( i = 0; i < N - 1; i + + ) / * * / { k = i; for( j = i + 1; j < N; j + + ) if( strcmp( name[ j], name[ k] ) < 0) k = j; if( k < > i) { temp = name[ k] ; name[ k] = name[ i] ; name[ i] = temp; printf( " : \ n" ) ; for( i = 0; i < N; i + + ) / * * / puts( name[ i] ) ; : : Li jun Wang xiaogang Che hong Shun dasheng Zhang zhigang : Che hong Li jun Shun dasheng Wang xiaogang Zhang zhigang,, s1 s2,, 0;, ASCII : s1 > s2,, s1 < s2, #include " stdio. h" { char s1[ 80], s2[ 80], * p1, * p2; int n, i; printf( " : " ) ; 96
104 5 gets( s1) ; printf( " : " ) ; gets( s2) ; p1 = s1; p2 = s2; /* p1 p2 s1 s2 * / while( * p1 = = * p2) /*, * / { if( * p1 = = \0 ) /* * / break; p1 ++ ; /* * / p2 ++ ; n = * p1 - * p2; printf( " : % d \ n", n) ; : : abcde : abcde : 0 : : fghijklmn : fghijopq : - 5, n = strcmp( s1, s2) /* \0, * / 5. 1? 5. 2?? 5. 3 * ( 1 ) num[ 5] ( 2 ) data[ k + 1] ( 3) array[ 6] [ 4] a, " Fortran program", " Fortr", 5. 7, ( 1 ) " efg" " abcdefghijk" 5, , 97
105 C " student" " ustdent" n 5. 13, 98
106 6, C, C, C, C ( C ),, C C C 6. 1 C C,,, 4 : ;, ; ; 3 x = sqrt( 12. 3) ;,, 12. 3,, x strcmp( str1, str2), char, str1 < str2, ; 0; str1 > str2,, int. h, #include sqrt math. h, strcmp string. h 99
107 C C ANSI C : int strcmp( char * str1, char * str2) strcmp int, char, C scanf( ) printf( ), ( 1 ) printf( ) printf( ) : printf(, ) ; printf( ) :,, ( ) int n = 25; float x = ; printf( " x = % f, n = % d \ n", x, n) ;, " x = % f, n = % d \ n" x n, % f % d x n : : % % (, % ), printf ( ),x =, n = \ n,, : : : x = , n = 25 printf( " % f* % d = % f \ n", x, n, x* n) ; * 25 = %, : % 0 m. n l h %,, 0m. n l h,, 100 l h l h,, 6. 1 : long % ld % lx % lo % lu double % lf % le % lg m. n A., m, n
108 6 m. n,, n : float x = ; printf( " % 12. 5f, % 5. 0f, % 0. 3f \n", x, - x, x) ; 6. 1 d x int char int x = 123; printf( " % d", x) ; 123 int char int x = 123; printf( " % x", x) ; 7b o u int char int x = 123; printf( " % o", x) ; 173 int char int x = - 123; printf( " % u", x) ; 131 ld lxlo long long x = 34567; printf( " % ld", x) ; lu hd hx ho short short x = 123; printf( " % hd", x) ; 123 hu c char char x = 65; printf( " % c", x) ; A s char * p = " ABC" ; printf( " % s", p) ; f float float x = ; printf( " % f", x) ; e float float x = ; printf( " % e", x) ; e g float float x = ; printf( " % g", x) ; e f ABC lf le lg double double x = ; printf( " % lf", x) ; : , - 123, , 3, 5,, 12 5, 0,, 1 m = 0,, 3,, % f 6, % lf 16 :,, 6 ( ), B., m, n n m n m, : char * s = " ABCDEFG" ; printf( " % 5. 3s \ n", s) ; 101
109 C : ABC printf( " % 5s\ n", s) ; ABCDEFG +,, -, : : ABC char * s = " ABCDEFG" ; printf( " % s \ n", s) ; : float x = ; printf( " % f \ n", x) ; : , 0 : float x = ; : printf( " % f\ n", x) ; ( 2 ) scanf( ) scanf( ) : scanf(, ) ; scanf( ) :, ( ) : scanf( " % f% d", &x, &n) ; " % f% d" &x&n, % f % d &x &n, ( Tab ) : : % % (, % ), scanf ( ), : scanf( " x = % f, n = % d", &x, &n) ;, x = 1. 23, n = 10, : x = 1. 23, n = 10 x =, n =,,, scanf, scanf,, : : 102 printf( " x, n = " ) ; scanf( " % f, % d", &x, &n) ;
110 6 x, n = 1. 23, 10,, : 4 ) : scanf( " % d: % d: % d", &hour, &minute, &second) ;, : 12: 30: 15 %, : % * m l h l h, m,, ( 6 ) ( scanf( " % 6d% 4f", &xh, &cj) ; : xh , cj % * : scanf( " % 3d% * 3d% 3c% 4d", &x, &ch, &y) ; : x 123, ch 7, y , 789 ch, ch, scanf( ) int,, EOF, 0,, : while( scanf( " % f", &x) ) s = s + x;, % f, scanf( ) , C, , : 103
111 C ( ) { ; ;, static static, 7. 1 int, ;, void 6. 1 float float trapezoid( int a, int b, int h) / * trapezoid( ), int a, b, h, ; * / { return ( a + b) * h / 2. 0; / * * / 6. 2 max( int x, int y) { if ( x > y) 6. 3 int return x; return ( y) ; void / * max( ) x y * / void display( int n) /* display( ), int n* / { int i, j; for( i = 1; i < = n; i + + ) { for( j = 1; j < = i; j + + ) return; printf( " % 2c", * ) ; printf( " \ n" ) ; return n 3, 3 * : * * * * * * ( ), { float trapezoid( int a, int b, int h) : float trapezoid( a, b, h) int a, b, h;, :, C, : 104 float trapezoid( int a, b, h)
112 6, ( ) void,, : int func( void), : int func( ) 6. 4 void dispstar( void) / * dispstar( ) * / { int i; for( i = 1; i < = 10; i + + ) / * 10 * / printf( " " ) ; for( i = 0; i < 60; i + + ) / * 60 * * / printf( " * " ) ; printf( " \ n" ) ; auto ( ) register,, 6. 7, return return : return( ) ; return ; return; ;, return ;, 3 4 5, int int trapezoid( int a, int b, int h) { return ( a + b) * h /2. 0; ,,, trapezoid( ) float, : empty( ) {, empty,, , : ( ) ; : 105
113 C float trapezoid( int, int, int ) ; 3 int, : ( ) ; : float trapezoid( int x, int y, int z) ;, a, b, h,, : float trapezoid( ) ;,,,,, 6. 5 float float_func( long) ; / * float_func * / { long long_func( int), a, b; / * long_func * / int n, c, d; float x; x = float_func( a) ; n = int_func( c) ; / *, int * / b = long_func( d) ; float float_func( long y ) / * float_func float * / { long long_func( int p ) / * long_func long * / { int_func( int z ) / *, int_func int * / { :, float_func( ), int, int_func( ), 6. 5, float_func long_func, : float float_func( long y ) / * float_func * / 106
114 6 { long long_func( int p ) / * long_func * / { { long a, b; / * long_func float_func * / int n, c, d; float x; x = float_func( a) ; n = int_func( c) ; / *, int * / b = long_func( d) ; int_func( int z ) / *, int_func int * / { ( 1 ), return : ( ),, 3 :, 6. 3 : display( 5) ;, ( ) 5 n 6. 1 : sum = 8* trapezoid( 4, 5, 6) ;, a b h, a 4, b 5, h , sum ( sum float ) a, b, c ( ) : m = max( a, max( b, c) ) ; a = 9 b = 15 c = 3,, b c x y, max( b, c) 15, max( a, 15) ; 15, m 15 : printf( " max = % d \ n", max( a, max( b, c) ) ) ;,, a b c,, max( ), : max = 15 ( 2 ), : 107
115 C,,,,,,,, 6. 6 C n m = #include " stdio. h" m! n! ( m - n)! long fact( int) ; / * fact( ) * / { int n, m; long cmn, fact( int) ; printf( " Enter m and n: " ) ; scanf( " % d, % d", &m, &n) ; cmn = fact( m) /( fact( n) * fact( m - n) ) ; / * fact( ) cmn * / printf( " cmn = % ld \ n", cmn) ; long fact( int x) { long m = 1; for( ; x > 1; x - - ) / * for, x 1 * / m = m* x; / * x * / return m; / * m * / : Enter m and n: 15, 10 cmn = 3003,, ( ) ( ) ( ),,, 6. 3,,,,, 108
116 #include " stdio. h" ( ) int swap( int x, int y) ; /* swap( ) * / { int a = 88, b = 66; printf( " : a = % d, b = % d \ n", a, b) ; swap( a, b) ; /* swap( ) * / printf( " : a = % d, b = % d \ n", a, b) ; int swap( int x, int y) / * swap( ) * / { int temp; : printf( " : x = % d, y = % d \ n", x, y) ; temp = x; x = y; y = temp; printf( " : x = % d, y = % d \ n", x, y) ; : a = 88, b = 66 : x = 88, y = 66 : x = 66, y = 88 : a = 88, b = x y, a b? a b x y swap( ),, a x, b yswap ( ) x y, a b ( 6. 1 ), ,, 6. 2, 6. 6, 6. 8 #include " stdio. h" ( ) int swap( int * x, int * y) ; { int a = 88, b = 66; printf( " : a = % d, b = % d \ n", a, b) ; 109
117 C swap( &a, &b) ; / * * / printf( " : a = % d, b = % d \ n", a, b) ; int swap( int * x, int * y) / * * / { int temp; printf( " : * x = % d, * y = % d \ n", * x, * y) ; temp = * x; * x = * y; * y = temp; / * * x * y a b * / printf( " : * x = % d, * y = % d \ n", * x, * y) ; & [ ] : : a = 88, b = 66 : * x = 88, * y = 66 : * x = 66, * y = 88 : a = 66, b = 88 2, 6. 3,,,, 6. 9 ( ) #include " stdio. h" #define N 20 float mean( int * data, int n) / * data * / { int i; float aver = 0; for( i = 0; i < n; i ++, data ++ ) / * * / aver + = * data; aver / = n; / * * / return ( aver) ; / * * / { int i, a[ N] ; float av; / * mean( ), * / for( i = 0; i < N; i ++ ) / * * / 110
118 6 scanf( " % d", a[ i] ) ; av = mean( a, N) ; / * mean( ), a, data * / printf( " Mean: % f\ n", av) ; / * * / a data, data a ( 6. 4),, * data a,,,, &a [ 0 ] 6. 4 a,, p: int i, a[ N], * p = a; av = mean( p, N) ;, mean : float mean( int data[ ], int n) data, data,,!, 6. 10,, ( ) #include " stdio. h" #define N 20 int maxdata( int data[ ], int n) ; int movedata( int * data, int mi) ; { int i, a[ N], m; for( i = 0; i < N; i + + ) / * * / scanf( " % d", a[ i] ) ; m = maxdata( a, N) ; / * maxdata( ), * / movedata( a, m) ; / * movedata( ), * / for( i = 0; i < N; i + + ) / * * / printf( " % d \ t", a[ i] ) ; printf( " \ n" ) ; int maxdata( int data[ ], int n) / *, data[ ] * / { int i, max, mi; max = data[ 0] ; 111
119 C for( i = 1; i < n; i + + ) / * * / if ( max < data[ i] ) mi = i; / * max * / return ( mi) ; / * * / int movedata( int * data, int mi) { int i, mx; / *,, data, * / mx = data[ mi] ; / * mx * / for( i = mi; i > 0; i - - ) / * * / data[ i] = data[ i - 1] ; data[ 0] = mx; / * * / return; / * * /,,,, char char,, char, ; #include " stdio. h" int strlen( char s[ ] ) ; { char * str = " c program" ; int len; len = strlen( str) ; / * * / printf( " The first string \ s length: % d \ n", len) ; len = strlen( " fortran languige" ) ; / * * / printf( " The second string\ s length: % d \ n", len) ; int strlen( char s[ ] ) / * strlen( ) * / { int n; for( n = 0; * s! n ++ ; return ( n) ; : The first string s length: 9 = \0 ; s + + ) The second string s length: 16 strlen( ),, 112
120 6 6. 4,,, : * ( ), static : int * s( int a, char ch) ; int s,, int : * ( ) ; : int * s( ), i, n; / * int s i n * /, return 6. 12,, : #include " string. h" / * strcmp( ) * / char * maxstr( char * ps[ ], int n) { char * max; int i; max = ps[ 0] ; / * maxstr( ), ps * / for( i = 1; i < n; i ++ ) / * max * / if ( strcmp( max, ps[ i] ) < 0) max = ps[ i] ; return ( max) ; / * max * /, maxstr( ), : #include " stdio. h" /* gets( ) * / #define N 10 { char * s[ N], * p, * maxstr( char * ps[ ], int n) ; int i; /* maxstr( ) * / 113
121 C for( i = 0; i < N; i + + ) gets( s[ i] ) ; /* N * / p = maxstr( s, N) ; /* maxstr( ), * / printf( " The max string is % s \ n", p) ; /* * / ,,,, 6. 13, 3 : : s, htoi( s) s a, htoi( char * ps) :, ps,, ctod( ),, 114 ctod( char c) : c d : #include " stdio. h" long htoi( char * ps) ; / * long htoi( ) * / char ctod( char c) ; / * char ctod( ) * / { char * s[ 80] ; long a; printf( " Enter a hexadecimal number: " ) ; scanf( " % s", s) ; / * * / a = htoi( s) ; / * htoi( ), * / if ( a < 0) else printf( " Input error! \ n" ) ; / * a < 0, * / printf( " The decimal number is % ld \ n", a) ; /* * / long htoi( char * ps) / * long htoi( ), ps * / { char * p; int i, d; long n = 0; for( p = ps; * p! = \ 0 ; p + + ) / * ps * / { d = ctod( * p) ; / * ctod( ), d * /
122 6 if ( d < 0) else return - 1; / * * p,, - 1* / n = n* 16 + d; / * * / return ( n) ; / * n * / ctod( char c) / * int ctod( ), c char * / { int d; if ( c > = 0&& c < = 9 ) else d = c - 0 ; / * c * / if ( c > = a&& c < = f ) else d = c - a + 10; / * c a f * / if ( c > = A&& c < = F ) d = c - A + 10; / * c A F * / else d = - 1; / * c,, d - 1 * / return ( d) ; / * d * /, ,, htoi( ) 6. 5 htoi( ) c tod( ) c tod( ) 6. 12,, 4, 3, 3, 3, 20,?,,,, 20,,,,,,,, ;,,,, ,,, : long fact( int n) { if ( n = = 1) else return ( 1) ; n! = n( n - 1 )! ( n > 1 ) 1 ( n = 1) return ( n* fact( n - 1) ) ; / * * / 115
123 C fact( 5), fact( 5) 6. 6, n,,, n, ,, n, n,,,,, auto C,,,,, ( Tower of Hanoi) 3, 6. 7, 64,,,,,, 6. 7 A B C, A n, n A B C hanoi( n, a, b, c), : 116 C A n - 1 B, hanoi( n - 1, a, c, b) n A C A B n - 1 C, hanoi( n - 1, b, a, c) : #include " stdio. h"
124 6 void hanoi( int n, char a, char b, char c) ; { int n; printf( " Input number of diskes: " ) ; scanf( " % d", &n) ; printf( " The step to moving % d diskes: \n", n) ; hanoi( n, A, B, C ) ; void hanoi( int n, char a, char b, char c) { if ( n = = 1) printf( " % c - > % c \ n", a, c) ; / *, " A - > C" * / else { hanoi( n - 1, a, c, b) ; printf( " % c - > % c \n", a, c) ; hanoi( n - 1, b, a, c) ; : Input number of diskes: 3 The step to moving 3 diskes: A - > C A - > B C - > B A - > C B - > A B - > C A - > C C,,,,, C,,,,, : ( * ) ( ) ;,, : 117
125 C int ( * f1) ( ), ( * f2) ( ) ; / * int f1 f2 * / int * pfunc( ), ifunc( ) ; / * int pfunc( ) int ifunc( ) * / f1 = pfunc; / * f1, f1 pfunc( ) * / f2 = ifunc; / * f2, f2 ifunc( ) * / : : int ( * f1) ( ) ;, int * f1( ) ; f1 ( ),,, : ( 1 ) *,, ( * ) ( ) ; *,,,, int f1( int x, int y) int f2( char ch), fs: int ( * fs) ( ) ;, : fs = f1; / * fs f1( ) * / x = ( * fs) ( a, b) ; / * x = f1( a, b) ; * / fs = f2; / * fs, fs f2( ) * / y = ( * fs) ( str) ; / * y = f2( str) ; * /,,, ( 2 ), : : : #include " stdio. h" #define N 5 { int maxnum( int x[ ], int n ), minnum( int x[ ], int n ) ; int sumnum( int x[ ], int n ) ; int func( int x[ ], int n, int ( * fun) ( ) ) ; / * * / int a[ N], i; printf( " Enter % d integer numbers: \ n", N) ; for( i = 0; i < N; i + + ) / * a * / scanf( " % d", &a[ i] ) ; 118
126 6 printf( " max = " ) ; func( a, N, maxnum) ; / * func( ) a, maxnum * / printf( " min = " ) ; func( a, N, minnum) ; / * func( ) a, minnum * / printf( " sum = " ) ; func( a, N, sumnum) ; / * func( ) a, sumnum * / func( int x[ ], int n, int ( * fun) ( ) ) / * fun * / { int result; result = ( * fun) ( x, n) ; / * fun * / printf( " % d \ n", result) ; maxnum( int x[ ], int n) { int max = x[ 0], k; for( k = 1; k < n; k + + ) if ( max < x[ k] ) max = x[ k] ; return ( max) ; minnum( int x[ ], int n) { int min = x[ 0], k; for( k = 1; k < n; k + + ) if ( min > x[ k] ) min = x[ k] ; return ( min) ; sumnum( int x[ ], int n) { int sum = 0, k; for( k = 0; k < n; k + + ) sum + = x[ k] ; return ( sum) ; : Enter 5 integer numbers: max = 33 min = 10 sum = 110 ( 3 ),, 119
127 C #include " stdio. h" #define N 5 { int func1( int, int), func2( int, int), func3( int, int), func4( int, int) ; int execute( int, int, int) / * * / int ( * function[ 4] ) ( ) ; / * int * / int a, b, i; function[ 0] = func1; / * * / function[ 1] = func2; function[ 2] = func3; function[ 3] = func4; a = 20; b = 5; for( i = 0; i < 4; i ++ ) /*,, execute( ), * / printf( " func No. % d > % d \n", i + 1, execute( a, b, function[ i] ) ) ; execute( int x, int y, int ( * func) ( ) ) / * func * / { return( ( * func) ( x, y) ) ; / *, * / func1( int x, int y) { return ( x + y) ; func2( int x, int y) { return ( x - y) ; func3( int x, int y) { return ( x* y) ; func4( int x, int y) { return ( x /y) ; : func No. 1 > 25 func No. 2 > 15 func No. 3 > 100 func No. 4 > ,,, 120
128 C 4, auto( ) register( ) static ( ) extern( ), auto register,,, auto, C auto, C, auto, auto, auto register CPU,,, register, ( 2 ), short static,, static 0 extern, static, , ( ), auto register static,,,, ;, ( ),, ( static ) static,, #include " stdio. h" int other( int n) ; { int i, n; / * auto i n * / static int a; / * static a * / register int b; / * register b * / i = 1; a = 10; b = 100; n = 5; if( a < b) { int t; / * auto t, t * / 121
129 C t = a; a = b; b = t; if( printf( " t = % d \ n", t) < 0) printf( " MAIN: error \ n" ) ; printf( " MAIN i: % d a: % d b: % d \ n", i, a, b) ; other( n) ; / * other * / printf( " MAIN i: % d a: % d b: % d \ n", i, a, b) ; other( n) ; int other( int n) { int i = 0; : / * t, t, printf( ) < 0 * / static int a = 20; / * static a, 20 * / i = i + 10; a = a + 20; n = i + a + n; printf( " OTHER i: % d a: % d n: % d \ n", i, a, n) ; MAIN: error MAIN i: 1 a: 100 b: 10 OTHER i: 10 a: 40 n: 55 MAIN i: 1 a: 100 b: 10 OTHER i: 10 a: 60 n: 75 : other( ) b, t t other( ) i a,,,, i a ( ),, i a,, C static,, other( ) a,, a = 20, a = a ;, a, a 40, a = a other( ) i,, i = 0, i = i ,, i ;, i 0, i = i auto,, auto register, static 0 122, ( 6. 19) ( )
130 6 str m n, string,, : char * strcut( char * str, int m, int n) / * strcut( ) * / { char string[ 80] ; int i; / * str, * / for( i = 0; i < n; i ++ ) / * string, m m - 1 * / string[ i] = str[ m + i - 1] ; string[ i] = \0 ; / * string * / return ( string) ; / * string * /, : { static char s[ ] = " Computer science" ; char * strcut( char * str, int m, int n ), * p; / * strcut( ) * / p = strcut( s, 10, 7) ; / * strcut( ), * / printf( " % s\ n", p) ; / * * /, string, auto,,,, p string static,,, m + n s,? #include " stdio. h" : int maxmin( float x[ ], int n) ; float max; / * max n * / int n = 100; { extern float min; / * min * / int i; float a[ 10] ; for( i = 0; i < 10; i + + ) / * a * / scanf( " % f", &a[ i] ) ; maxmin( a, 10) ; / * * / printf( " max = % f, min = % f \n", max, min) ; / * max min * / float min; / * min * / int maxmin( float x[ ], int n) / * * / { int i; max = min = x[ 0] ; 123
131 C for( i = 1; i < n; i + + ) if ( max < x[ i] ) max = x[ i] ; else if ( min > x[ i] ) min = x[ i] ; :, max min maxmin( ), n maxmin( ) n, maxmin( ), n n, min, extern extern, C 4, ( auto register ) ( static ),,,,,,,,,,,,,,, auto register CPU static extern,, : ( static ) ( static ) ( ) 6. 8, C ;,,,, 124
132 6 ;,,,,,, C ( 1) malloc malloc void *, malloc( size ), size unsigned int malloc size,,, void,, char, ( NULL),, : int float * pi; * pf; pi = ( int* ) malloc( sizeof( int) ) ; / * pi int * / pf = ( float* ) malloc( sizeof( float) ) ; / * pf float * / if ( pi! = NULL) / * * / * pi = 123; if ( pf! = NULL) * pf = ; ( int* ) *, int int,, : pi = ( int* ) malloc( 2) ; pf = ( float* ) malloc( 4) ; malloc ( 2) calloc malloc, n, calloc calloc void *, calloc( n, size), n size unsigned int size,, calloc, 0 : char * pc; pc = ( char* ) calloc( 80, sizeof( char) ) ; / * pc 80 char * /, calloc malloc calloc, free : free( p) ; p, p, p free , realloc realloc void *, 125
133 C realloc( p, size), p, size unsigned intrealloc p sizesize,, : int * pi; float * pf; pf = ( float* ) malloc( sizeof( float) ) ; / * pf float * / pi = ( int* ) realloc( pf, sizeof( int) ) ; / * pf int * / ( C. Goldbach) : 6 #include " stdio. h" #include " math. h" / * sqrt( ) * / int prime( long) ; { long n, a, b, c; printf( " : " ) ; scanf( " % ld", n) ; for( a = 6; a < = n; a + = 2) / * 6 * / { for( b = 3; b < = a /2; b + = 2) / * b * / if( prime( b) ) / * b * / { c = a - b; / * c * / if( prime( c) ) / * c,, b * / break; printf( " % ld = % ld + % ld \ n", a, b, c) ; / * * / prime( long x) / * * / { int flag = 1; / * flag, 1, 0 * / long i; for( i = 2; i < sqrt( x) ; i ++ ) if( x% i = = 0) / * x i,, * / { flag = 0; break; return ( flag) ; : :
134 6 6 = = = , ; del_str( ) ; del_char( ) #include " stdio. h" char * del_str( char str[ ], char ch) ; / * del_str( ) : * / { char s[ 80], dc; / * s[ 80] :, dc: * / printf( " : " ) ; gets( s) ; printf( " : " ) ; getchar( dc) ; del_str( s, dc) ; / * * / printf( " : % s \ n", s) ; char * del_str( char str[ ], char ch) { int i; char * del_char( char * st, int k ) ; / * : st k * / for( i = 0; i < strlen( str) ; i ++ ) if ( str[ i] = = ch) { del_str( str, i) ; / * * / i - - ; / * * / return ( str) ; char * del_char( char * st, int k) { int i; i = k; while( i < strlen( st) - 1) st[ i] = st[ i + 1] ; / *, 6. 8 * / return ( st) ; : : Information science : i : Informaton scence 6. 8, del_str del_char( str, i) ; strcpy( &str[ i], &str [ i + 1] ) ; del_char( ) x 3-2x 2 + 5x - 8 = 0, 10-5 f( x), ( 6. 9) : f( x) x x 0 x 1, x 2 127
135 C f( x 1 ) f( x 2 ), x x, 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) < : f( x) x : x 3-2x 2 + 5x - 8; point( x1, x2) f( x1) f( x2 ) x x; root( x1, x2) ( x1, x2), #include " stdio. h" #include " math. h" float f( float x) ; float point( float x1, float x2) ; float root( float x1, float x2) ; { float x1, x2, x; do { printf( " Input x1, x2: " ) ; scanf( " % f, % f", &x1, &x2) ; 6. 9 / * x1 x2 * / while( f( x1) * f( x2) > = 0) ; / * f( x1) f( x2) * / x = root( x1, x2) ; / * root x * / printf( " A root of the equation is % 8. 5f", x) ; / * x * / float f( float x) / * f( ), f( x) * / { return ( ( ( x ) * x ) * x ) float point( float x1, float x2) / * point, x x * / { return ( ( x1* f( x2) - x2* f( x1) ) / ( f( x1) - f( x2) ) ) float root( float x1, float x2) / * root, * / { float x, y, y1; : 128 y1 = f( x1) ; / * f( ), f( x1) * / do { x = point( x1, x2) ; / * point( ) x x * / y = f( x) ; if( y* y1 > 0) / * f( x) f( x1), x x1 * / { y1 = y; x1 = x; else x2 = x; / * x x2 * / while ( fabs( y) > = 1e - 6) ; / * f( x) 10-6 * / return ( x) ;
136 6 Input x1, x2: 1, 9 A root of the equation is : 1 y1 = ( 1 + x + 0 x2 + x 3 ) dx 2. 5 y2 = ( 1 + x 2 ) dx y3 = 0 x dx 1 + x 2, f( x), b a, n, h = ( b - a) /n, 6. 10, : s = f( a ) + f( a + h) 2 h 2 h h + f( a + h) + f( a + 2h) 2 f( a + ( n - 1) h) f( b) h + h = 2 [ f( a) + 2f( a + h) + 2f( a + 2h) + + 2f( a + ( n - 1) h) + f( b) ] = f( a) + f( b) 2 + f( a + h) + f( a + 2h) + + f( a + ( n - 1) h), n, f( x) : float integral( float ( * f) ( ), float a, float b, int n) { float s, h, y; int i; s = ( ( * f) ( a) + ( * f) ( b) ) /2; h = ( b - a) /n; for( i = 1; i < n; i + + ) s = s + ( * f) ( a + i* h) ; y = s* h; / * f, f( x) * / return ( y) ; / * * / : float f1( float x) { return ( 1 + x + x* x + x* x* x) ; float f2( float x) { return ( 1 + x* x) ; float f3( float x) { return ( x/ ( 1 + x* x) ) ; : { float f1( float x), f2( float x), f3( float x) ; / * * / float integral( float ( * f) ( ), float a, float b, int n) ; float y1, y2, y3; int n = 100; y1 = integral( f1, 0, 1, n) ; 129
137 C : y2 = integral( f2, 0, 2. 5, n) ; y3 = integral( f3, 0, 3. 5, n) ; printf( " y1 = % 6. 3f\ ny2 = % 6. 3f\ ny3 = % 6. 3f\ n", y1, y2, y3) ; y1 = y2 = y3 = #include " stdio. h" int data[ ] = {11, 12, 13, 14, 15, 16, 17, 18, 19, 20; /* data * / int binary( int key, int low, int high) ; { int a, k; printf( " : " ) ; scanf( " % d", &k) ; a = binary( k, 0, 9) ; if( a = = - 1) printf( " % d \ n", k) ; else printf( " % d % d \ n", k, a) ; int binary( int key, int low, int high) { int mid; / * key:, high low: * / if( low > high) return ( - 1) ; /*, - 1 * / mid = ( low + high) /2; if( data[ mid] > x) /* * / return ( binary( x, low, mid - 1) ) ; else if( data[ mid] < x) /* * / else : return ( binary( x, mid + 1, high) ) ; return ( mid) ; /* * / : , s1 s2 strcat( s1, s2), , c1 s c2 strrpl( s, c1, c2 ), 130
138 , reverse( ), , 6. 6, x 3-5x x - 80 = 0 [ 2, 8] 6. 7, 7x 4 + 6x 3-5x 2 + 4x + 3 = , : y 1 = 7 ( 2 6x2 + 5x ) dx y 2 = sinxdx ,, 6. 11, str substr itob( n), n, reverse , n, 1, 1 5, 5,? a, part( a, m, n), m n, : 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20; m = 5, n = 10, : 1, 2, 3, 4, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 15, 16, 17, 18, 19, substr str insstr( str, ch, substr), ch str ch, malloc, 10, , n, : f( n) = 1 n = 0 1 n = 1 f( n - 1) + f( n - 2) n > , a b, : gcd( a, b) = b a% b = = 0 gcd( b, a% b) a% b! = 0 1
139 7 C, C,,, C, :,,,, 7. 1 C 7. 1 C ( 1 ) C C C ( 7. 1 ), : ;,,,,,,,, ( ),, 132
140 7 C,,, C C C,. CC, C C,, ( ) ( 10 ) 7. 2 C 7. 3,,,,,,, ( ) ,, ( 2 ) C, C,,,, A B 133
141 C A: B1 B2 B3 B4 B5 B6 B7 B8 B9 C31 C32 C33 C ( ) ***** ***** , 7. 5 void mainmenu( ) { char choice = 1 ; while( choice! = 0 ) { / * * / printf( " ***** ***** \ n" ) ; printf( " \ n" ) ; printf( " \ n" ) ; printf( " \ n" ) ; printf( " \ n" ) ; printf( " \ n" ) ; printf( " \ n" ) ; printf( " \ n" ) ; printf( " ( 09) : " ) ; choice = getchar( ) ; switch( choice) { case 1 : 134
142 7 C b1( ) ; break; / * * / case 2 : case 3 : b2( ) ; break; / * * / b3( ) ; break; / * * / case 4 : b4( ) ; break; / * * / case 5 : b5( ) ; break; / * * / case 6 : b6( ) ; break; / * * / case 7 : b7( ) ; break; / * * / case 8 : b8( ) ; break; / * * / case 9 : b9( ) ; break; / * * / case 0 : default: exit( 0) ; / *, * / printf( ", ( 09) : " ) ;, b3 ( ),, C31 C32 C33 C34,,, C ( 10 ) ( 1), static,,, extern 7. 6, file1. c file2. c file3. c int aa; extern char cc func1( ) { satic int bb; extern int aa; func2 ( ) { func2_1( ) { char cc; static int bb; func3( ) {extern int aa;
143 C file1 aa file2, file3 funo3 file3 cc file1, file2 bb file3 bb, 7. 2 int k; /* k * / { void pstar( ) ; for( k = 0; k < 5; k + + ) /* 5 * / pstar( ) ; /* 5 * * / void pstar( ) /* 5 * * / { for( k = 0; k < 5; k ++ ) printf( " % c", * ) ; printf( " \ n" ) ; : ***** 5, 5 *, pstar( ) k 5,,,,,, ( 2) file_1. c file_2. c extern int fun2( ) ; fun1( ) { extern int fun3( ) ; fun2( ) ; fun3( ) static int fun4( ) { extern int fun1( ) ; fun2 { fun3( ) { static int fun4( ) { fun1( ) ; 7. 7 static,,,, extern 7. 7, file_1 extern fun2 fun3, fun4, fun3 fun1 extern, fun3 ( ), file_2 fun1( ) fun4( ) file_1, , C,
144 7 C,,,,,,, 7. 3 / * exam1. c * / #include " stdio. h" extern void count( ) ; / * count( ) * / extern void find( ) ; / * find( ) * / char * name[ 50] ; / * * / int score[ 50] ; / * * / { int i; char select; for( i = 0; i < 50; i + + ) / * 50 * / { printf( " % d : ", i) ; gets( name[ i] ) ; printf( " % d : ", i) ; scanf( " % d", &score[ i] ) ; while( 1) / * * / { printf( " : A B C \ n" ) ; getchar( select) ; if ( select == A select == a ) count( ) ; /* count( ) * / else if( select == B select == b ) find( ) ; / * find( ) * / else exit( 0) ; / * * / / * exam2. c * / extern int score[ ] ; / *, * / void count( ) / * count( ) * / { int i; float aver = 0; for( i = 0; i < 50; i ++ ) / * 50 * / aver + = score[ i] ; aver / = 50; / * * / printf( " : % 6. 2f\ n", aver) ; return; 137
145 C / * exam3. c * / extern int score[ 50] ; / * * / extern char * name[ ] ; / * * / void find( ) / * find( ) * / { int i; char * sn, ch = y ; while( ch == y ch == Y ) { printf( " : " ) ; return; gets( sn) ; for( i = 0; i < 50; i + + ) / * * / if( strcmp( sn, name[ i] ) == 0) / * * / { printf( " % s : % d \ n", sn, score[ i] ) ; break; if ( i > = 5 0) printf( " \ n" ) ; printf( "? Y/ N " ) ; getchar( ch) ; 3, exam1. obj exam2. obj exam3. obj, C, 7. 2 C,, #,, ;, 3 : ( 1 ) : #define, C, 138,
146 7 C,, : #define R #define PI : circle = 2* PI* R; : circle = 2* * 10. 5;, 7. 4 #define WIDTH 60 #define LENGTH WIDTH + 40 #define PR printf { int area1, area2, area3; area1 = WIDTH* 5; / * area1 = 60* 5; * / area2 = LENGTH* 5; / * area2 = WIDTH + 40* 5; area2 = * 5; * / area3 = WIDTH* LENGTH; / * area2 = 60 * WIDTH + 40; area2 = 60 * ; * / PR( " area1 = % d, area2 = % d, area3 = % d \ n", area1, area2, area3) ; / * printf( " area1 = % d, area2 = % d, area3 = % d \ n", area1, area2, area3) ; * / PR( " WIDTH = % d, LENGTH = % d \n", WIDTH, LENGTH) ; / * printf(width = % d, LENGTH = % d \ n", 60, ) ; * / : area1 = 300, area2 = 260, area3 = 3640 WIDTH = 60, LENGTH = 100 :, printf PR, 60 WIDTH, LENGTH WIDTH, WIDTH,, LENGTH, : #define LENGTH ( WIDTH + 40) area2 = LENGTH* 5; area2 = ( ) * 5 area3 = WIDTH* LENGTH; area3 = 60* ( ),, printf( ) 139
147 C WIDTH LENGTH : ( 2 ) : : #define ( ) #define AREA( x) x* x + 5 z = AREA( 10) ;, 10 x,, : 7. 5 z = 10* ; #define POWER( x) ( ( x) * ( x) ) / * x * / #define MAX( x, y) ( x) > ( y)? ( x) : ( y) / * x y * / #define PR printf { int a, b, c, d, x; a = 5; b = 10; x = 2250; c = POWER( a + b) ; / * c = ( ( a + b) * ( a + b) ) ; * / x = x / POWER( a + b) ; / * x = x/ ( ( a + b) * ( a + b) ) ; * / d = MAX( a + 6, b) ; / * d = ( a + 6) > ( b)? ( a + 6)( b) ; * / PR( " c = % d, d = % d, x = % d \ n", c, d, x) ; : c = 225, d = 11, x = 10 : #define POWER( x) ( ( x) * ( x) ), : : #define POWER( x) ( x) * ( x) / * printf( " c = % d, d = % d, x = % d \ n", c, d, x) ; * / c = POWER( a + b) ; c = ( a + b) * ( a + b) ; c 225 x = x / POWER( a + b) ; x = x/ ( a + b) * ( a + b) ; x 2250 #define POWER( x) x* x c = POWER( a + b) ; c = a + b* a + b; c 65 x = x / POWER( a + b) ; x = x/ a + b* a + b; x 510, 140,
148 7 C,,,,,,, #undef : , 1 : #include " ",,,, 2 : #include < >,,,,, 7. 8, : 7. 8 file2. c file1. c #include " stdio. h" stdio. h stdio. h, type include, include 1 2 include, 2 3 include,
149 C,, #include 7. 6 cpublic. c: #define PI #define YES 1 #define NO 0 #define PR printf file1. c: cpublic. c, #include " cpublic. c" { : #if 1 #else 2 #endif,,, 1, 2 ; 2,, : #define DEBUG 1 #if DEBUG printf( " a = % d \ n", a) ; printf( " x = % f \n", x) ; #endif, DEBUG : #define DEBUG 0, : 1) 1 #ifdef 1 #else 2 #endif 142
150 7 C : ( #define ), 1, 2 : #ifdef IBM_PC #define INTEGER_SIZE 16 #else #define INTEGER_SIZE 32 #endif IBM_PC, INTEGER_SIZE 16 2 ) 2 #ifndef 1 #else 2 #endif :, 1, 2 1 ) , #include " stdio. h" #define SWAP( x, y) { int t; t = x; x = y; y = t; { int a, b, c; printf( " a, b, c: " ) ; scanf( " % d, % d, % d", &a, &b, &c) ; if ( a < b) SWAP( a, b) if ( a < c) SWAP( a, c) if ( b < c) SWAP( b, c) printf( " a, b, c : % d, % d, % d \ n", a, b, c) ; : a, b, c: 9, 3, 5 a, b, c : 9, 5, , #define LEAP_YEAR( year) year%4 ==0 && year% 100! = 0 year%400 ==0 / * * / { int year, month, day, n; do{ printf( " - - : " ) ; 143
151 C scanf( " % d - % d - % d", &year, &month, &day) ; if ( month < 1 month > 12 day < 1 day > 31 year < 0) printf( ",! \ n" ) else break; while( 1) ; / * * / n = days( year, month, day) ; / * * / printf( % d \ n, n) ; / * * / int days( int y, int m, int d) { int n = 0, mt[ ] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 ; / * mt * / : if ( LEAP_YEAR( y) ) mt[ 2] = 29; / * 2 * / for( i = 1; i < m; i + + ) n + = mt[ i] ; / * * / n + = d; / * * / return n; / * * /.. : , C 7. 2 swap( a, b),, 7. 3 #define max( a, b) ( ( a) > ( b)? ( a) : ( b) ) max( x, max( y, z) ) 7. 4 : #define MULT1( a, b) a* b #define MULT2( a, b) ( a) * ( b) y = MULT1( 3 + 5, ) ; z = MULT2( 3 + 5, 6 + 4) ; y z? 7. 5 C ,? 7. 8,, 7. 9,, 144
152 7 C
153 8 8. 1,, :, ;,,,,? C, ( Struct) , : struct student { char name[ 10] ; ; char sex[ 2] ; int age; int score;, ( : ), 4 ( : ) : ( name) ( sex) ( age) ( score ), struct C, student, student, struct, int char, : 146 struct stedent stu1, stu2; /* stu1, stu2* /
154 8 struct student, : struct stedent stua[ 100], * pstu;, stua struct student, pstu struct student,, ( ) C, : struct { 1 ; ; 2; n; C, C, : struct date / * struct date * / { int year; ; int month; int day; struct student_1 { char name[ 10] ; ; char sex[ 2] ; struct date birthday; / * birthday * / int score; struct student_1 stu3, stu4;, struct student_1 birthday struct date,, struct date, stu3, stu4 C,, : struct student { char name[ 10] ; char sex[ 2] ; int age; int score; stu1, stu2 = {" Wang", " ", 25, 88 ; / * stu1 stu2, stu2 * /,, : 147
155 C struct / * * / { char name[ 10] ; char sex[ 2] ; int age; int score; stu1, stu2 = {" Wang", " ", 25, 88;, stu1 stu2, stu2, ;,,,,,,,, ( 1 ),,,,, struct student stu1, : stu1. name[ 10] = " wang" ; stu1. sex[ 2] = " " ; stu1. age = 18; stu1. score = 95;.,,, :. : aver = ( stu1. score + stu2. score) /2; / * * / stu1, : scanf( " % s, % s, % d, % d", stu1. name, stu1. sex, &stu1. age, &stu1. score) ; printf( " % s, % s, % d, % d", stu1. name, stu1. sex, stu1. age, stu1. score) ;, struct student_1 stu3, : stu3. name[ 10] = " wang" ; stu3. sex[ 2] = " " ; stu3. birthday. year = 1980; stu3. birthday. month = 10; stu3. birthday. day = 18; stu3. score = 95;, stu3 birthday,, 148
156 8.,,,, C, ( 2 ),, : ; ; : ;, 8. 1, strut stu_score / * stu_score, * / { char name[ 8] ; / * 4 * / ; int english; int chinese; int math; int stu_aver_score( strut stu_score stuv) ; /* * / { strut stu_score stus, * stusp, stusa[ 100] ; int aver; scanf( " % s, % d, % d, % d", stus. name, &stus. english, &stus. chinese, &stus. math) ; aver = stu_aver_score( stus) ; / *, * / printf( " % s, % d, % d, % d, aver is: % d \ n", stus. name, stus. english, stus. chinese, stus. math, aver) ; int stu_aver_score( strut stu_score stuv) { int aver_score; aver_score = ( stuv. english + stuv. chinese + stuv. math) /3; / *, * / return( aver_score) ; / * * / : Enter a name and score for english, chinese, math: Lihua, 69, 75, 84 Lihua, 69, 75, 84, aver is: C ( ), ( 1 ) stua: strut student 149
157 C { char name[ 8] ; int age; int score; ; struct student stua[ 100] ; stua 100 struct student,,, : for( i = 0; i < 100; i + + ) scanf( " % s, % d, % d", stua[ i]. name, &stua[ i]. age, &stua[ i]. score) ; 100, ( 2 ) stup stua stuv: strut student { char name[ 8] ; int age; int score; ; struct student stuv, * stup, stua[ 100] ;,, stup : stup = &stuv; stup stuv, stup stuv, stup stuv : ( * stup). ame = " Wang" ; ( * stup). age = 18; ( * stup). score = 97; :( * ).,,, ( * stup ). name * stup. name, * ( stup. name),,, C ( ), : stup - > name = " Wang" ; stup - > age = 18; stup - > score = 97 ; - >, - > stup - > score stup score, stua : for( i = 0; i < 100; i + + ) / * i int * / scanf( " % s, % d, % d", ( stua + i) - > name, &( stua + i) - > age, &( stua + i) - > score) ; 150
158 8 : for( stup = stua; stup < stua + 100; stup + + ) /* stup struct student * * / scanf( " % s, % d, % d", stup - > name, &stup - > age, &stup - > score) ; ,, C,, struct mystruct, 8. 1 : 8. 1 Struct mystruct struct mystruct Struct mystruct struct mystruct struct mystruct & struct mystruct struct mystruct struct mystruct Struct mystruct struct mystruct 8. 2, 8. 1, strut stu_score / * stu_score, * / { char name[ 8] ; / * 4 * / int english; int chinese; int math; ; int stu_aver_score( strut stu_score * stuvp) ; / * * / { strut stu_score stus, * stusp; int aver; printf( " \ nenter a name and score for english, chinese, math: " ) ; scanf( " % s, % d, % d, % d", stus. name, &stus. english, &stus. chinese, &stus. math) ; stusp = &stus; aver = stu_aver_score( stusp) ; / * aver = stu_aver_score( &stus) ; * / printf( " % s, % d, % d, % d, aver is: % d \ n", stus. name, stus. english, stus. chinese, stus. math, aver) ; int stu_aver_score( strut stu_score * stuvp) / *, * / { int aver_score; 151
159 C aver_score = ( stuvp - > english + stuvp - > chinese + stuvp - > math) /3; / * * / return( aver_score) ; / * * / : Enter a name and score for english, chinese, math: Lihua, 69, 75, 84 Lihua, 69, 75, 84, aver is: 76, , ) :, ( struct box_type / * * / { int bl; / *, * / ; int bw; / * * / int bh; / * * / float price; / * * / struct box_type input( ) ; / *, * / float getval( struct box_type box2) ; / *, * / { struct box_type box; / * box * / float value; / * box * / box = input( ) ; / * box, * / value = getval( box) ; / * box, * / printf(box\ s long: % d, width: % d, high: % d, material price: % f, value is % f\ n, box. bl, box. bw, box. bh, box. price, value) struct box_type input( ) / *, * / { struct box_type box1; 152 printf( " \ nenter box\ s long, width, high and material price: " ) ; scanf( " % d, % d, % d, % f ", &box1. bl, &box1. bw, &box1. bh, &box1. price ) ; return ( box1) ; / * * / float getval( struct box_type box2) / *, * / { int bs; float tv; bs = box2. bl* box2. bh* 6 + box2. bw* box2. bh* 2; / * * / tv = bs* box2. price; / * * / return ( tv) ;
160 8 : Enter box s long, width, high and material price: 5, 4, 4, 2. 5 Box s long: 5, width: 4, high: 4, material price: , value is , struct box_type / * * / { int bl; / * * / ; int bw; / * * / int bh; / * * / float price; / * * / void input( struct box_type * p_box1) ; / *, * / float getval( struct box_type * p_box2) ; / *, * / { struct box_type box; / * box * / float value; / * box * / input( &box) ; / * box, * / value = getval( &box) ; / * box, * / printf( " \ nbox \ s long: % d, width: % d, high: % d, material price: % f, value is % f", box. bl, box. bw, box. bh, box. price, value ) void input( struct box_type * p_box1) / *, * / { printf( " \ nenter box\ s long, width, high and material price: " ) ; scanf( " % d, % d, % d, % f", &p_box1 - > bl, &p_box1 - > bw, &p_box1 - > bh, &p_box1 - > price ) ; return; / * * / float getval( struct box_type * p_box2) / *, * / { int bs; float tv; bs = p_box2 - > bl* p_box2 - > bh* 6 + p_box2 - > bw* p_box2 - > bh* 2; / * * / tv = bs* p_box2 - > price; / * * / return ( tv) ; : Enter box s long, width, high and material price: 5, 4, 4, 2. 5 Box s long: 5, width: 4, high: 4, material price: , value is , , #define N, , 5, 5 ( ) strut stu_score / * stu_score, * / { char name[ 8] ; / * 4 * / int english; 153
161 C int chinese; int math; ; strut stu_score aver_score( strut stu_score stusav[ ], int n) ; / * * / void stu_input( strut stu_score * stup, int n) ; / * * / { strut stu_score stusa[ N] ; strut stu_score aver ; /* aver * / stu_input( stusa, N) ; / *,, * / aver = aver_score( stusa, N) ; / *,, * / printf( " Average english is: % d, chinese is % d, math is % d \ n", aver. english, aver. chinese, aver. math) ; void stu_input( strut stu_score * stup, int n) / *, * / { int i; for( i = 0; i < N; i + +, stup + + ) { printf( " \ nenter a name and score for english, chinese, math: " ) ; scanf( " % s, % d, % d, % d", stup - > name, &stup - > english, &stup - > chinese, &stup - > math) ; strut stu_score aver_score( strut stu_score stusav[ ], int n) / *, * / { strut stu_score aver1 = { " ", 0, 0, 0 ; / * * / int i; for( i = 0; i < n; i + + ) ; /* * / { aver1. english = aver1. english + stusav[ i]. english; aver1. chinese = aver1. chinese + stusav[ i]. chinese; aver1. math = aver1. math + stusav[ i]. math; aver1. english = aver1. english / n; / * * / aver1. chinese = aver1. chinese / n; aver1. math = aver1. math / n; return ( aver1) ; / * * / : Enter a name and score for english, chinese, math: Lihua, 69, 75, 84 Enter a name and score for english, chinese, math: Wang, 70, 83, 64 Enter a name and score for english, chinese, math: Huwei, 79, 88, 77 Enter a name and score for english, chinese, math: Yanzi, 90, 70, 83 Enter a name and score for english, chinese, math: Mali, 92, 89, 87 Average english is: 80, chinese is 81, math is , 154
162 C : strut student { char name[ 8] ; ; int age; int score; strut student * next; / * * /, ( strut student ) next,, strut student next, 8. 1 head ne xt 8. 1, next,, ( nod), head struct student,, next, NULL,,,, C C, ( 1), ( ), ( ) ( ) ( NULL ) ( ),,,,,,,,, ( ) ( ) ( 2),, ( table),,, 155
163 C :,, 3 : ; ;,, 13 2 A,,,,,,,,, ,, ( LIFO) ( FIFO), ( 1),,,, NULL,,, 8. 2 : head : strut student { char name[ 8] ; ; int age; int score; strut student * next; ne xt 8. 2, : struct student struct student * ps ; / * ps * / for( ps = head; ps! = NULL; ps = ps - > next ) / * * / NULL printf( " % s, % d, % d \ n", ps - > name, ps - > age, ps - > score) ; / * * / : void search( struct student * ps) /* head * / { if( ps = = NULL ) / * * / printf( " The end! " ) ; /* * / else { printf(% s, % d, % d \ n, ps - > name, ps - > age, ps - > score) ; / * * / search( ps - > next) ; / * * /, ps, ps, ps, 156
164 8 ( ),,, ( ),, : struct student * ps; for( ps = head; ps - > next! = NULL; ps = ps - > next ) / *, * / / * * / printf( " % s, % d, % d \ n", ps - > next - > name, ps - > next - > age, ps - > next - > score) ; ( 2),,,,, struct stendent, : struct student * pt ; pt = ( struct student* ) malloc( sizeof( struct student) ) ; / *, * / scanf( " % s, % d, % d", pt - > name, &( pt - > age), &( pt - > score) ) ; / * * / pt - > next = head; / * * / head = pt; / * head * / : struct student * pt, * ps; pt = ( struct student* ) malloc( sizeof( struct student) ) ; / * * / scanf( " % s, % d, % d", pt - > name, &( pt - > age), &( pt - > score) ) ; / * * / for( ps = head; ps - > next! = NULL; ps = ps - > next) ; / *, ps * / ps - > next = pt; / * * / pt - > next = NULL; /* * / :,, : for( ps = head; ps! = NULL; ps = ps - > next) ; ps NULL,, : if( head == NULL) / * * / { head = pt; / *, head * / else pt - > next = NULL; { for( ps = head; ps - > next! = NULL; ps = ps - > next) ; / *, ps * / ps - > next = pt; / * * / pt - > next = NULL; /* * /, struct student, age,,,, :,, 8. 3 struct student, head struct student * pt, * ps ; pt = ( struct student* ) malloc( sizeof( struct student) ) ; /* * / 157
165 C 8. 3 pt - > name = " Wang" ; / * * / pt - > age = 18; pt - > score = 85; for( ps = head; ps - > next! = NULL && ps - > next - > age < = 18; ps = ps - > next) ; / *, age 18, ps * / / * age 18, ps * / if( ps - > next == NULL) / * * / { ps - > next = pt; / *, * / pt - > next = NULL; / * * / else / * * / { pt - > next = ps - > next; / * * / ps - > next = pt;, : age 18, ps,,,,,, ( ), ( 3) :, ; : struct student, age 18 struct student * pt, * ps; for( ps = head; ps - > next! = NULL && ps - > next - > age! = 18; ps = ps - > next) ; / *, age 18, ps * / / * age 18, ps * / if( ps - > next = = NULL) /* * / printf( "! " ) ; else / * * / 158
166 8 { pt = ps - > next; / * pt, ps * / ps - > next = ps - > next - > next; / * * / free( pt) ; / * * /, ( ) ,, , 3,, struct employee / * * / { char name; int age; int salary; struct employee * next; ; int creat( struct employee * phead) ; / * * / void display( struct employee * phead) ; / * * / int delete( struct employee * phead) ; / * * / struct employee * head = NULL ; / * * / { int i; for( i = 0; i < 100; i ++ ) / * * / if(! creat( head) ) / * * / break; / * * / display( head) ; / * * / for( ; delet( head) ; ) / * * / display( head) ; / * * / int creat( struct employee * phead) / * * / { struct employee * ps, * pt; if( phead == NULL) / * phead * / { phead = ( struct employee * ) malloc( sizeof( struct employee) ) ; phead - > next = NULL; / * phead * / if( ( pt = ( struct employee * ) malloc( sizeof( struct employee) ) ) = = NULL) ; / * * / { printf( " error! " ) ; / * * / return( 0) ; / * * / printf( " Enter a employee name, age, salary: " ) ; scanf( " % s, % d, % d", pt - > name, &( pt - > age), &( pt - > salary) ) ; / * * / for( ps = phead; ps - > next! = NULL && ps - > next - > age < = pt - > age; ps = ps - > next) ; / *, age, ps * / 159
167 C /* age, ps * / if( ps - > next = = NULL) / * * / { ps - > next = pt; / * * / pt - > next = NULL; / * * / else / * * / { pt - > next = ps - > next; / * * / ps - > next = pt; head = phead; / * * / return( 1) ; / * * / void display( struct employee * phead) / * * / { struct employee * ps; if( phead = = NULL) / * phead * / else printf( " No massage! " ) ; { for( ps = phead; ps - > next! = NULL && ps - > next - > age < = pt - > age; ps = ps - > next) /* * / printf( " % s, % d, % d \ n", ps - > next - > name, ps - > next - > age, ps - > next - > salary) ; int delete( struct employee * phead) / * * / { struct student * pt, * ps ; for( ps = phead; ps - > next! = NULL && ( ps - > next - > age > = 30 && ps - > next - > age < = 35) ; ps = ps - > next; / *, age 30-35, ps * / / * age 30-35, ps * / if( ps - > next = = NULL) / * * / { printf( "! " ) ; return( 0) ; else / * * / { pt = ps - > next; / * pt * / ps - > next = ps - > next - > next; / * * / free( pt) ; head = phead; / * * / return( 1) ; , : : 160
168 8 strut student { char name[ 8] ; int age ; int score ; strut student * next ; / * * / strut student * last ; / * * / ; 8. 5, ( strut student ) next last,, strut student next last, 8. 5, last NULL,, next NULL,, ( ),, ( last ) ( next ),, : strut student { char name[ 8] ; int age, score; strut student * left; / * * / strut student * right; / * * / ;, ( strut student ) left right, 8. 6,, ( ) ( root) : void search( struct student * ps) / * ps * / { if ( ps! = NULL) { search( ps - > left) ; printf( " % s, % d, % d \n", ps - > name, ps - > age, ps - > score) ; search( ps - > right) ;,,,,, C,, C C,,,, 161
169 C 8. 6 :, C ( Object Oriented Programming OOP), OOP ( Object), ( ), ( Class), ( Object) ( Instance), , C, : : union data { int n; ; char c; float f; union { 1; ; 2 ; n ;, 3 : n c f union C, data data, union 162
170 8, int char, : union data d1, d2, d3[ 100], * pd;, d1 d2 union data, d3 union data, d3 union data, pd union data,,, n c f, ( ), ( ) ( ),,,, C, ,,., union data d1, : d1. n = 25; : d1. c = A ; : d1. f = ;,, &d1 &d1. n &d1. c &d1. f,, : d1. n = 25; d1. c = A ; d1. f = ; 3, d1. f = ,,, :,, 8 double, : union temp { double d; ; char db[ 8] ; union temp dsen, drec; double m, : dsen. d = m; dsen. db[ 0 ] dsen. db[ 7 ], drec. db[ 0] drec. db[ 7], 8, drec. d double 163
171 C 8. 5,,,, : enum weekday { sun, mon, tue, wed, thu, fri, sat ; /* * / enum weekday workday, otherday; / * * / 1, 7, sun mon... satenum C, weekday weekday, enum 2 enum weekday workday otherday, sun mon tue wed thu fri sat : workday = mon; otherday = sun; sun mon... sat,, sun, sd, :, C : sun = 0; mon = 1;, C 0, 1, 2,, sun 0, mon 1,, sat 6: workday = mon; printf( " % d", workday) ; 1, : enum weekday { sun = 7, mon = 1, tue, wed, thu, fri, sat; sun 7, mon sat 1 6 : ( ) : if( workday > otherday) if( workday = = mon) : workday = ( enum weekday) 2; workday = tue;, 164
172 A B C D E { enum sclass {a = 9, b = 8, c = 7, d = 6, e = 5 ; / * * / enum sclass sc; /* * / int score, n; printf( " \ nenter a score: " ) ; scanf( " % d", &score) ; / * score * / for( ; score > 100 score < 0; ) ; / * score * / { printf( " \ nscore must between 0 100, Please againe: " ) ; scanf( " % d", &score) ; / * * / n = ( score - score% 10) /10; / * int n * / n = n > 9? 9: n; / * n * / n = n < 5? 5: n; sc = ( enum sclass) n; / * n enum sclass * / switch( sc) { case a: peintf( " \ nthe class is A" ) ; break; case b: peintf( " \ nthe class is B" ) ; break; case c: peintf( " \ nthe class is C" ) ; break; case d: peintf( " \ nthe class is D" ) ; break; case e: peintf( " \ nthe class is E" ) ; break; default: break; : Enter a score: 89 The class is B : Enter a score: 599 Score must between 0 100, Please againe: 59 The class is D 8. 6 typedef C, typedef ( C ), : typedef int INTEGER; typedef float REAL; INTEGER intreal float, : INTEGER a, b, c; : int a, b, c; 165
173 C REAL x, y, z; : float x, y, z;, INTEGER REAL? : : struct date { int month; ; : int int typedef struct day; year; { int month; int int DATE; day; year;, DATE, DATE, : DATE birthday; : struct date birthday; DATE : struct date * * pdate; pdate;,, C typedef : typedef int INTARR[ 100] ; / * INTARR 100 * / INTARR n; : int n[ 100] ; typedef char * STRING; / * STRING char * * / STRING p, s[ 10] ; : char * p, * s[ 10] ; /* p, s * /, typedef,, C : typedef,,, typedef typedef #define, : typedef int INTEGER; #define INTEGER int INTEGER int, #define,, typedef, C, typedef,, 166
174 C?? 8. 2,,? 8. 3 student, student, sdate, student 8. 5,, student, 8. 7,,, , ( ) 8. 9,,, ( ) ( ) ( FIFO), 167
175 9, C,, C ( bit) C, C ( bit),, ( Word) ( Byte),, bit ; 4, 4 bit, bit 1 0,,, C, ( ) C 9. 1 C : 9. 1,, & ( int or Word) ( char or Byte) ^, ( float) ( 1 ) ( &) << &, 1, >> 1, 0, : 0 & 0 = 0; 0 & 1 = 0; 1 & 0 = 0; 1 & 1 = 1; : 3&5 1, : 168
176 9 3 : & 5 : : 1 : C : char a = 3, b = 5, c ; c = a & b;, c 1 ( bit) 0, ( bit), : a( 2 ) 0: a = a & oxff ; / * byte, byte * / a( 2 ) 3 0 1: c = a & ox04 ; / * c 1 1, 0 * / ( 2 ) ( ), 1, 1, 0, : 0 0 = 0; 0 1 = 1; 1 0 = 1; 1 1 = 1; : 3&5 7, : 3 : : : 7 : C : char a = 3, b = 5, c ; c = a b;, c 7 ( bit) 1, : char a 4 ( bit) 1 : a = a 0xf0 ; /* 4 1, 4 * / char a 3 ( bit) 1 : a = a 0x04 ; / * 3 ( bit) 1, * / ( 3 ) ( ^) ^, ( ), 1, 0 : 0 ^ 0 = 0; 0^1 = 1 ; 1 ^ 0 = 1; 1 ^ 1 = 0; : 3&5 6, : 3 : ^ 5 : : 6 : C : char a = 3, b = 5, c ; c = a ^ b; 169
177 C, c 6 : 0, 1 ( bit), 1 0, 0 1, : char a 4 ( bit) : a = a ^ 0xf0 ; / * 4, 4 * / char a 3 ( bit) : a = a ^ 0x04 ; /* 3 ( bit), * / ( 4 ) ( ),,, ( bit), 1 0, 0 1, : 0 = 1; 1 = 0; : 9 0xf6, : 9 : : : C : char a = 9, c ; c = a;, c 0 xf6, 0, : a = a & 1; / * * / ( 5 ) ( << ) <<, ( bit), 0 : 3 1 6, : << 3 : : 6 : C : char a = 3, c ; c = a << 1; a 2, : << 3 : : C : char a = 3, c; c = a << 2;, c 12, ( 1 ), 1, 2 ( 6 ) ( >> ) >>, ( bit) : 170
178 9 12 6, : >> 12 : : 6 : C : char a = 12, c; c = a >> 1;, c 6, a 2, 3, ( 0) ( 1 ), 1, 2 0,, 0, 1 ( ), 0 1?, 0 ; 1, 0x8c,, 0xc6,, 0x46 ( 7 ) 1 ) ( int char ), C :,, : int a = 17; char b = - 3; a = a ^ b; a b, ( ) : a : ^ b : a : ) C C : a = a & b; a & = b; c = c >> 1; c >> = 1;, = ^= << = C 9. 2,,, 1 bit, 1,, 9. 1, a b c d bit,,, C?,, ( bit), unsigned : 171
179 C struct pack_data { unsigned a : 2; / * " : " 2 2 bit, * / ; unsigned b : 6; unsigned c : 5; unsigned d : 3; int n; struct pack_data data_1; data: a b c d data_1 struct pack_data, 5, 4, 4 a b c d 2 :,, data_1 data_1. a = 2; data_1. b = 7; data_1. c = 25; data_1. d = 6; data_1. n = 100; data_1: a b c d n 9. 2 data_1 data _ 1 4 : ( 9. 2 ), : struct pack_data { unsigned a : 2; / * " : " 2 2 bit * / ; unsigned b : 3; unsigned c : 4; unsigned d : 3; int n; struct pack_data data_2; data_2: a b c d n data_2 data_2 a b c d 12 bitc,, a b 5, 3, 172
180 9 8 c d 7, 1 data_2 9. 3, : data_1. a = 8;, 3,,, data_1. a 0, 1, C, :,, : struct pack_data { unsigned a : 3; ; unsigned b : 6; /* 5 bit, b * / unsigned c : 2;, : struct pack_data { unsigned a : 3; ; unsigned : 0; / * * / unsigned b : 6; / * b * / 8,, : printf( " % d, % d", data_1. a, data_1. b) ;, % u % o % x, : data_1. a + 6 /data_1. b ? 1 char a, 3 ( 1 0 ),, 1 ( &), 0, 0, int test( char a) { if( a & 8) / * 8 3 1, 0 * / printf( " switch is on! " ) ; 173
181 C 9. 2 else printf( " switch is off! " ) ; return a 4 4, , , { int a, b, c; printf( " Input a: " ) ; scanf( " % d", &a ) ; / @ & 4, 8 4 * / printf( " Before a = % xh \ n", a) ; / * a * / b = a; / * b * / c = a & 0x0ff0; / * c , a 8 * / a << = 12; / * a &&&& , 4 4 * / b >> = 12; / * @, 4 4 * / a = b; / * * / a = c; / * * / printf( " After a = % xh \ n", a) ; / *a * / : Input a: 115 Before a = 73H After a = 3070H,, : { struct data 174 { unsigned a : 4; ; unsigned b : 4; unsigned c : 4; unsigned d : 4; union u_data { struct data m; ; int n; union u_data v; scanf( " % d", &v. n ) ; /* v. n * / printf( " \ nbefore is: % d \ n", v. n ) ; v. m. a ^= v. m. d; v. m. d ^= v. m. a; v. m. a ^= v. m. d; / * v. m. a v. m. d * / printf( " \ nafter is: % d \ n", v. n ) ;
182 9 : C, ( D0 D2 D4 D14 ), 9. 2, 9. 3 : 4 4, 9. 4 getbit, int bit : unsigned getbit( int value, int n1, int n2) : int value n1 n bit,, 1,,,
183 C ( file) ( ),, PC, ( byte),,, 3 : ( text),,, ASCII, GB,,,, ( CPU), CPU CPU,, CPU ( ),,,,,,. ini,,, C,,? 176
184 10 C ( ),,, ( ASCII ),,, 100, 2 ( ), 3 ( ), ASCII,,,,,,,, CPU,,,, C, :, : C,,,,, 10. 1, C ( ANSI C), C C,,,? FILE : FILE * fp ; fp FILE?, stdio. h : typedef struct { int _fd ; / * * / int _cleft ; / * * / int _mode ; / * * / char * _nextc ; / * * / char * _buff ; / * * / FILE ;, FILE,, 177
185 C FILE C, FILE FILE fp, FILE, C FILE 10. 2,,,, ( fopen ) C, fopen( ), stdio. h, : FIILE* fp ; fp = fopen(, ) ; : fp = fopen( " mydat. dat", " r" ) ; " mydat. dat", " r" : fopen( ) mydat. dat ( ), FILE, fp, fp mydat. dat, fopen( ) NULL,, : if ( ( fp = fopen( " mydat. dat", " r" ) ) == NULL) { 10. 1, fopen ( ) 3 : " r" " w" ( ) " a" ( ) " rb" ( char* ) " wb" " ab" ( ),, " r + " /, : " w + " / fp = fopen( " a: \\ data \\ mydat. dat", " r" ) ; " a + " / ( ) a data mydat. dat " rb + " / ( char* ) " wb + " /, " ab + " / ( ) 178
186 10 : " r" " rb" " r + " " rb + ",, fopen ( ) NULL " r" " rb" ( ), " r + " " rb + " ( ) ( ) " w" " wb" " w + " " wb + ",, fopen ( ) ( ), fopen( ), " w" " wb" ( ), " w + " " wb + " ( ) ( ) " a" " ab" " a + " " ab + ", ( ), fopen ( ) NULL " a" " ab" ( ), " a + " " ab + " ( ) ( ),,,, C, 3 : 3 stdin stdout stderr C : stdout = fopen( " prn", " w" ) ;, printf( ), " prn" ( fclose ),, C fclose( ), : : fclose( ) ; fclose( fp) ; / * fp * / fp?,, fp, fp,,,,,,, 3, 179
187 C 10. 3, C, stdio. h, ( # include) stdio. h fputc fgetc ( 1 ) fputc ( ) : fputc( ch, fq) ; ch char, fp FILE, ch fp( fopen ), fputc ch, EOFEOF stdio. h, - 1 stdio. h : # define putchar( c) fputc( c, stdout), putchar( ),, fputc( ), : fputc( ), ( 2 ) fgetc ( ) : ch = fgetc( fp) ; ch char, fp FILE, fp( fopen ) ( ), ch fputc( ), fgetc( ), fgetc( ),,, fgetc( ) EOF,, : ch = fgetc( fp) ; / * fp * / while( ch! = EOF) / *, * / { putchar( ch) ; ch = fgetc( fp) ;, - 1, C ( ) 180
188 10, feof( ) feof( ) : while(! feof( fp) ) / * fp * / { c = fgetc( fp) ; feof( fp) 1( ), 0 ( ),,, c,, stdio. h : # define getchar( c) fgetc( c, stdin), getchar( ),, fgetc( ), ( 3 ) 10. 1,, # # include " stdio. h" { FILE * fp ; : char ch, fname[ 10] ; printf( " \ nenter a filename: " ) ; scanf( " % s", fname ) ; if ( ( fp = fopen( fname, " w" ) ) = = NULL) / * ( ) * / { printf ( " Cannot open file \ n" ) ; exit ( 0) ; / *, * / while ( ( ch = getchar( ) )! = " #" ) { fputc( ch, fp) ; / * * / putchar( ch ) ; / * * / printf( " \ no. K! \ n" ) ; / * * / fclose( fp) ; / * * / Enter a filename: mywords. c ( ) I love china # I love china O. K! ( ) ( ),, fname : C stdio. h : #define putc( ch, fp) #define getc( fp) fputc( ch, fp) fgetc( fp), putc( ) getc( ) fputc( ) fgetc( ) 181
189 C fwrite fread fputc( ) fgetc( ) C, fputc ( ) fgetc( ), C, fwrite( ) fread( ) : ( 1 ) fwrite : fwrite( buffer, size, count, fp) ; buffer:, size: int, ( ) count: int, ( size ) fp: FILE fp( fopen) : struct student { char name[ 8] ; ; int age ; int score ; char addr[ 30] ; struct student stu ; fwrite( &stu, sizeof( struct student), 1, fp) ; / * stu fp * /, stu struct student, fwrite( ) : fwrite( ), count ( 2 ) fread : fread( buffer, size, count, fp) ; buffer:, buffer 182 size: int, ( ) count: int, ( size ) fp: FILE ( ) struct student, : struct student stu ; fread( &stu, sizeof( struct student), 1, fp) ; / * stu* /
190 10 fread( ), count, fread( ),,, fwrite( ), ( 3 ) , student. dat #include " stdio. h" #define SIZE 5 struct student { char name[ 8] ; int age ; int score ; char addr[ 30] ; ; int savedata( struct student stua[ ], int m) ; volid read_print( ) ; { struct student stua[ SIZE] ; int n ; for ( n = 0; n < SIZE; n + + ) scanf( " % s, % d, % d, % s", stua[ n]. name, &stua[ n]. age, &stua[ n]. score, stua[ n]. addr) ; if( savedata( stua, SIZE) ) read_print( stua, SIZE) ; int savedata( struct student stua[ ], int m) /* savedata : student. dat, m stua * / { FILE* fp ; int i ; if( ( fp = fopen( " student. dat", " wb" ) ) == NULL ) /* * / { printf ( " cannot open out file! \ n" ) ; return ( 0) ; / *, 0* / for ( i = 0; i < m; i + + ) fwrite( &stua[ i], sizeof( struct student), 1, fp) ; / * stua[ i] * / fclose( fp) ; / * * / return ( 1) ; / *, 1* / volid read_print( ) /* read_print( ) : student. dat * / { struct student stu ; FILE * fp ; if( ( fp = fopen( " student. dat", " rb" ) ) = = NULL ) / * * / 183
191 C { printf ( " cannot open out file! \ n" ) ; exit ( 0) ; printf( " \ n" ) ; while(! feof( fp) ) { fread( &stu, sizeof( struct student), 1, fp) ; / * struct student * / printf( " % s, % d, % d, % s\ n", stu. name, stu. age, stu. score, stu. addr) ; fclose( fp) ; / * * / fread fwrite, C, ( ), fread fwrite, fread fwrite, fread,, ( ) ( buffer ), fread fwrite C,, ( fprintf fscanf ) fprintf( ) fscanf( ) printf( ) scanf( ), : printf( ) scanf( ), fprintf( ) fscanf( ) : : fprintf(,, ) ; fscanf(,, ) ; fprintf( fp, " % s: % 6. 2f", name, score) ; / * fp * / char* name float score,, fp name " Wang" score , : Wang: : fprintf( stdout, " % s: % 6. 2f", name, score) ; : printf( " % s: % 6. 2f", name, score) ;, fscanf( ) : fscanf ( fp, " % s: % f", name, &score) ; / * fp * / fp : 184 Wang:
192 10 " Wang" name, score, fprintf( ), fscanf( ),,, fprintf( ),,, fprintf( ),,,, fprintf( ) fscanf( ) student. dat student. rep # include " stdio. h" struct student { char name[ 8] ; ; int age ; int score ; char addr[ 30] ; { struct student stu ; FILE * dat, * rep ; / * * / if ( ( dat = fopen( " student. dat", " rb" ) ) = = NULL) /* * / { printf ( " cannot open out file! \ n" ) ; return ( 0) ; if ( ( rep = fopen( " student. rep", " w" ) ) = = NULL) / * * / { printf ( " cannot open out file! \ n" ) ; return ( 0) ; while(! feof( dat) ) { fread( &stu, sizeof( struct student), 1, dat) ; /* struct student * / fprintf( rep, " % s, % d, % d, % s \n", stu. name, stu. age, stu. score, stu. addr) ; /* student. rep* / printf( " % s, % d, % d, % s\ n", stu. name, stu. age, stu. score, stu. addr) ; fclose( dat) ; fclose( rep) ; fgets fputs /* * / fgets( ) fputs( ) fgets( ) : fgets( str, n, fp) ; /* str char*, n int, fp * / : n - 1, str 185
193 C n - 1,, \0 str ( str ) fputs( ) : fputs( " china", fp ) ; / * fp * / : " china" fp 0, 0 fgets( ) fputs( ) gets( ) puts( ), : gets( ) puts( ), fprintf( ) fscanf( ) : fputs( " china", stdout ) ; : puts( " china" ) ; C,,,, : ( C ), " r" " rb" " r + " " rb + " " w" " wb" " w + " " wb + ",,,,,, C rewind rewind( ) rewind( ) student. dat, 186 # include " stdio. h" struct student { char name[ 8] ; ; int age ; int score ; char addr[ 30] ; { struct student stu ; FILE* fp ; / * * / scanf( " % s, % d, % d, % s\ n", stu. name, &stu. age, &stu. score, stu. addr) ;
194 10 / * * / if ( ( fp = fopen( " student. dat", " ab + " ) ) = = NULL) / * " ab + " * / { printf ( " cannot open out file! \ n " ) ; return ( 0) ; fwrite( &stu, sizeof( struct student), 1, fp) ; / * stu * / / * * / rewind( fp ) ; / * * / while(! feof( fp) ) { fread( &stu, sizeof( struct student), 1, fp) ; / * struct student * / printf( " % s, % d, % d, % s\ n", stu. name, stu. age, stu. score, stu. addr) ; / * * / fclose( fp ) ; fseek,, rewind( ),, C, fseek( ) : fseek( ) : fseek( fp, 100L, 0) ; fseek(,, ) ; : fp 100, 101 : fp FILE*, 100L long ( C, L, long ),,, C long 3, 0 1 2, 0, 1, 2 stdio. h : #define SEEK_SET 0 #define SEEK_CUR 1 #define SEEK_END 2 fseek( ) 3 fseek( ),, fseek( ) : fseek( fp, 100L, 0) ; / * 100 * / 187
195 C fseek( fp, 1000L, 1) ; / * 1000 * / fseek( fp, 150L, 2) ; / * 150 * / student. dat, student. dat struct student, struct student 42, name 8,, 34 # include " stdio. h" struct student { char name[ 8] ; int age ; int score ; char addr[ 30] ; ; { char stu_name[ 8] ; FILE* fp ; / * * / if ( ( fp = fopen( " student. dat", " ab + " ) ) == NULL) / * " ab + " * / { printf ( " cannot open out file! \ n " ) ; return ( 0) ; while(! feof( fp) ) { fread( stu_name, 8, 1, fp) ; / * name * / printf( " % s\ n", stu_name) ; / * * / rewind( fp, 34L, 1 ) ; / * 34 * / fclose( fp ) ; ftell ftell( ), ftell( ) long, - 1 L : s = ftell( fp ) ; / * s long, fp FILE* * / if ( s == - 1L) printf( " error! \ n" ) ; s ( ), ( ), " error! " ,, Windows
196 10, DOS C ferror C, ( ),,, ferror( ) : ferorr( fp) ;, ferror( ) 0 ( ),, 0 ( ),, ferorr( ), ferror( ), ferror( ) : , #include " stdio. h" { FILE * fp ; char ch, fname[ 10], err_flag = 0 ; / * err_flag * / printf( " \ nenter a filename: " ) ; scanf( " % s", fname ) ; if ( ( fp = fopen( fname, " w" ) ) == NULL ) / * ( ) * / { printf ( " cannot open file \ n " ) ; exit ( 0) ; while ( ( ch = getchar( ) )! = " #" ) { fputc( ch, fp) ; / * * / if ( ferorr( fp ) ) / * * / { err_flag = 1 ; / * * / break ; putchar( ch ) ; / * * / if ( err _flag) printf( " \ nwrite disk err! " ) ; / * * / else printf( " \ no. K! " ) ; / * * / : Enter a filename: mywords. c ( ) I love china # ( ) I love china ( ) O. K! 189
197 C clearerr clearerr ferror( ) 0( ),, clearerr( ),, rewind( ), ( mywords. c) ( youwords. c) DOS COPY, # include " stdio. h" main( int argc, char* argv[ ] ) { FILE* f_in, * f_out ; char databyte ; if ( argc < 3 ) / * * / { printf( " Please enter command again! \ n" ) ; / *, * / exit( 0) ; if ( ( f_in = fopen( argv[ 1], " rb" ) ) = = NULL ) / * * / { printf ( " cannot open in file! \ n " ) ; exit ( 0) ; if ( ( f_out = fopen( argv[ 2], " wb" ) ) = = NULL ) / * * / { printf ( " cannot open out file! \ n " ) ; exit ( 0) ; for( ;! feof( f_in ) ; fputc( fgetc( f_in ), f_out) ) ; / *, * / fclose( f_in) ; fclose( f_out) ; printf( " \ no. K! \n " ) ; / * * / / * * / for( f_out = fopen( argv[ 2], " r" ) ;! feof( f_out ) ; putchar( fgetc( f_out ) ) ) ; printf( " Is all right? \ n" ) ; / * * / exam. c, exam. exe, : exam mywords. c youwords. c ( ) O. K! I love china ( ) Is all right? muti. rep, : 1* 1 = 1 190
198 10 1* 2 = 2 2* 2 = 4 1* 3 = 3 2* 3 = 6 3* 3 = 9 1* 9 = 9 9* 9 = 81,, # include " stdio. h" { int m, n ; FILE * rep ; /* * / if( ( rep = fopen( " muti. rep", " w + " ) ) = = NULL) /* * / { printf ( " cannot open out file! \ n" ) ; return ( 0) ; for ( m = 1 ; m < = 9; m + + ) { for ( n = 1 ; n < = m; n ++ ) fprintf( rep, " % d* % d = % d", n, m, n* m) ; / * muti. rep* / fprintf( " \ n" ) ; /* * / rewind( rep) ; / * * / for ( ;! feof( rep) ; putchar( fgetc( rep) ) ) ; / * * / fclose( rep) ; / * * / student. dat, # include " stdio. h" struct student { char name[ 8] ; int age ; int score ; char addr[ 30] ; ; { struct student * stu, * top_stu ; / * top_stu * / int top_score = 0 ; / * * / FILE * fp ; / * * / if ( ( fp = fopen( " student. dat", " rb" ) ) = = NULL) / * " rb" * / { printf ( " cannot open out file! \ n " ) ; return ( 0) ; fread( top_stu, sizeof( struct student), 1, fp) ; / * top_stu 1 * / while(! feof( fp) ) { fread( stu, sizeof( struct student), 1, fp) ; / * stu * / 191
199 C if( stu - > score > top_stu - > score ) /* * / top_stu = stu ; /* top_stu * / printf( " % s, % d, % d, % s\ n", top_stu - > name, top_stu - > age, top_stu - > score, top_stu - > addr) ; /* * / rewind( fp) ; /* * / while(! feof( fp) ) /* * / { fread( stu, sizeof( struct student), 1, fp) ; / * struct student * / printf( " \ n% s, % d, % d, % s", stu - > name, stu - > age, stu - > score, stu - > addr) ; / * * / fclose( fp ) ; 10. 1, C , ( #) , ( # ), ( ASCII 4), 10. 6, ( ), ( ) , 3, 5 3,, stud stud 5, stud_sort stud _sort 5 stud_aver 192
200 1 1 C C,, C C, MS-DOS Windows MS-DOS PC ROM-BIOS, ( ) ROM-BIOS, DOS,,, ( ), ;,, C,,,, Windows DOS, API( ), Windows SDK Windows ROM-BIOS C ROM-BIOS, int86( ), : int int86( int IntNo, union REGS* r_in, union REGS* r_out) : IntNo ; r_in REGS, ; r_out, : 193
201 C int86( ) AX int86( ) dos. h, REGS dos. h : struct WORDREGS{ unsigned int ax, bx, cx, dx, si, di, cflag, flags; ; struct BYTEREGS{ unsigned char al, ah, bl, bh, cl, ch, dl, dh; ; union REGS{ struct WORDREGS x; struct BYTEREGS h; ; REGS h x, ax al ah ROM-BIOS PC, 1AH, 02H 04H, AH ;, CH CL DH DL, ( BCD ), 4 : #include " stdio. h" #include " dos. h" { union REGS r_in, r_out; r_in. h. ah = 0x04; / * 04H, * / int86( 0x1A, &r_in, &r_out) ; / * 1AH, * / printf( " date: % 2x% 02x - % x - % x\ n", r_out. h. ch, r_out. h. cl, r_out. h. dh, r_out. h. dl) ; / * * / r_in. h. ah = 0x02; / * 02H, * / int86( 0x1A, &r_in, &r_out) ; / * 1AH, * / printf( " time: % 2x: % 02x: % 02x \ n", r_out. h. ch, r_out. h. cl, r_out. h. dh) ; 11. 2, / * : : * /, 25 80,, ROM-BIOS 10H,, H 02H,, : AH = 02H DH ( 0-24) DL ( 0-79) BH, 0 09H,, : AH = 09H BH, 0 AL BL, CX, 0, 8 : 7 : 1,
202 11 C 6-4 :, : : 1, :,, : #include " stdio. h" #include " dos. h" void SetCursorPosition( int row, int column) ; / * * / void PutCharProperty( char c, char property) ; /* * / { SetCursorPosition( 12, 20) ; / * * / PutCharProperty(A, 0x41) ; / * ,,, * / void SetCursorPosition( int row, int column) { union REGS r_in, r_out; / * * / r_in. h. dh = row% 25; r_in. h. dl = column% 80; r_in. h. bh = 0; / * 0* / r_in. h. ah = 0x02; / * 02H, * / int86( 0x10, &r_in, &r_out) ; / * 10H * / void PutCharProperty( char c, char property) { union REGS r_in, r_out; r_in. h. al = c; / * * / r_in. h. bl = property; / * * / r_in. h. bh = 0; / * 0* / r_in. h. cx = 1; / * 1* / r_in. h. ah = 0x09; / * 09H, * / int86( 0x10, &r_in, &r_out) ; / * 10H * /, DOS DOS, 21H, DOS DOS, int86( ), 0x21, intdos( ), 21H, : int intdos( union REGS* r_in, union REGS* r_out) : r_in, ; r_out, : 195
203 C intdos( ) AX intdos( ) dos. h DOS H, : AH = 36H DL, 0, 1 A, 2 B, 3 C,, : AX, FFFFH BX ( ) CX DX C : #include " dos. h" #include " stdio. h" { union REGS r_in, r_out; long free; r_in. h. dl = 0x03; / * C * / r_in. h. ah = 0x36; / * 36H* / intdos( &r_in, &r_out) ; /* DOS 36H* / printf( " Total number of clusters: % u \ n", r_out. x. dx) ; / * * / printf( " Number of available cluters: % d \n", r_out. x. bx) ; /* * / printf( " Sectors per cluster: % d \ n", r_out. x. ax) ; / * * / printf( " Bytes per sector: % d \ n", r_out. x. cx) ; / * * / free = 1L* r_out. x. bx* r_out. x. ax* r_out. x. cx/1024; printf( " Free total: % ldkb\ n", free) ; / * KB * / DOS 47H, : AH = 47H DL, 0, 1 A, 2 B, DS: SI, : DS: SI ASCII, PC C, DS, C DS, SI C : #include " stdio. h" #include " dos. h" { union REGS r_in, r_out; char buffer[ 65] ; r_in. h. ah = 0x47; /* 47H* / r_in. h. dl = 0x03; / * C * / r_in. x. si = ( int) buffer; / * * / 196
204 11 C intdos( &r_in, &r_out) ; / * DOS 47H* / if ( r_out. x. cflag) / * * / printf( " Drive number is invalid! \ n" ) ; else printf( " Current directory is: \ \ % s \ n", buffer) ; / * C * / C dos. h inportb( ) outportb( ), PC inportb( ),, outportb( ) PC 2, 2, 0x43 0x PC 8255 B D1 2, D0 D1 D0 1,, ; D1 D0 0,, #include " dos. h" #include " stdio. h" void MySound( unsigned frequency, long delay) ; / * * / { MySound( 262, L) ; MySound( 294, L) ; MySound( 330, L) ; MySound( 349, L) ; MySound( 392, L) ; MySound( 440, L) ; MySound( 493, L) ; MySound( 523, L) ; /*, frequency ; delay,, 197
205 C * / void MySound( unsigned frequency, long delay) { union { unsigned value; struct { unsigned char low; unsigned char high; h; LSB; unsigned char temp; long i; LSB. value = ul / frequency; / * * / outportb( 0x43, 0xB6) ; / * 2 3* / outportb( 0x42, LSB. h. low) ; / * * / outportb( 0x42, LSB. h. high) ; / * * / temp = inportb( 0x61) ; / * 8255 B temp * / outportb( 0x61, temp 0x03) ; / * temp 1 B, * / for( i = 0; i < delay; i + + ) ; / * * / outportb( 0x61, temp&0xfc) ; / * temp 0 B, * / 11. 3, PC, Turbo C 2. 0DOS ( ), Windows API Direct Draw, Open GL Turbo C 2. 0, C, graphics. h ( 1) void initgraph( int* graphdriver, int* graphmode, char* pathtodriver) ;,, initgraph( ) 3 graphdriver ( ), graphmode ( ), pathtodriver, BGI, EGAVGA. BGIEGA VGA, TC
206 11 C TC2. 0, EGAVGA. BGI graphics. h : enum graphics_drivers / * define graphics drivers* / { DETECT, /* requests autodetection* / ; CGA, MCGA, EGA, EGA64, EGAMONO, IBM8514, / * 1-6* / HERCMONO, ATT400, VGA, PC3270, / * 7-10* / CURRENT_DRIVER = - 1 enum graphics_modes / * graphics modes for each driver* / { / * CGA EGA * / ; VGALO = 0, / * color 4 pages* / VGAMED = 1, / * color 2 pages* / VGAHI = 2, / * color 1 page* / PC3270HI = 0, / * page* / IBM8514LO = 0, / * colors* / IBM8514HI = 1 / * colors* /, VGA 3, VGALO( , 16, 4 ) VGAMED( , 16, 2 ) VGAHI( , 16, 1 ) VGAMED, EGAVGA. BGI C TC, : int gd = VGA, gm = VGAMED; initgraph( &gd, &gm, " C: \ \ TC" ) ;,, : int gd = DETECT, gm; initgraph( &gd, &gm, " " ) ; ( 2) void closegraph( void) ;,, initgraph( ), ( ) : closegraph( ) ; ( 3) : void setactivepage( int page) : void setvisualpage( int page), VGALO, 4 ; VGAMED, 2 ; VGAHI, 1,,, ( 0 199
207 C ), VGALO, 2, : setactivepage( 1) ; setvisualpage( ), 1 : setvisualpage( 0) ; ( 4) void cleardevice( void) ;, ( 0, 0) 3, : setactivepage( 2) ; / * 3 * / cleardevice( ) ; / * ( 3 ) * / ( 1) void setcolor( int color), void setbkcolor( int color) graphics. h, : enum COLORS { BLACK, BLUE, GREEN, CYAN, RED, MAGENTA, BROWN, LIGHTGRAY, DARKGRAY, LIGHTBLUE, LIGHTGREEN, LIGHTCYAN, LIGHTRED, LIGHTMAGENTA, YELLOW, WHITE ;, : setcolor( GREEN) ; : setcolor( 2) ; 2 GREEN,, : setbkcolor( BLUE) ; setcolor( 1) ; ( 2) void putpixel( int x, int y, int color) ( x, y) ( 100, 80), : putpixel( 100, 80, RED) ; unsigned getpixel( int x, int y) ( 20, 30), : c = getpixel( 20, 30) ; 200
208 11 C, ( 20, 30) c ( 3) : void line( int x1, int y1, int x2, int y2) ; void lineto( int x, int y) ; void moveto( int x, int y) ; void setlinestyle( int linestyle, unsigned user_pattern, int thickness) ; line( ) ( 10, 20 ) ( 150, 50), : line( 10, 20, 150, 50) ; lineto( ), ( 200, 80), : lineto( 200, 80) ; moveto( ), lineto( ) moveto( ), ( 50, 0) ( 100, 50) ( 60, 80), : moveto( 50, 0) ; lineto( 100, 50) ; lineto( 60, 80) ; lineto( 50, 0) ; SOLID_LINE DOTTED_LINE CENTER_LINE DASHED_LINE USERBIT_LINE setlinestyle( ), linestyle linestyle USERBIT _LINE, user_pattern ( 16 ) user_pattern, 1, 0 linestyle USERBIT_LINE, user_pattern 0 thickness : NORM_WIDTH( 1) THICK_ WIDTH( 3 ) NORM_ WIDTH, THICK_WIDTH, : setlinestyle( DOTTED_LINE, 0, NORM_WIDTH) ; ( 4) : void circle( int x, int y, int radius) ; void ellipse( int x, int y, int stangle, int endangle, int xradius, int yradius) ; circle( ), ( 100, 80), 30( ), : circle( 100, 80, 30) ; ellipse( ) ( x, y), stangle, endangle, xradius yradius x y : ellipse( 150, 100, 0, 180, 40, 30) ; 201
209 C ( 5) : void rectangle( int left, int top, int right, int bottom) ; void drawpoly( int numpoints, int* polypoints) ; rectangle( ), ( left, top), ( right, bottom) : rectangle( 10, 20, 80, 50) ; drawpoly( ),,, numpoints, polypoints, ( x, y), : int v[ ] = {50, 10, 100, 10, 120, 60, 30, 60, 50, 10 ; drawpoly( 5, v) ; ( 1) : void setfillpattern( char* upattern, int color) ; void setfillstyle( int pattern, int color) ; setfillpattern ( ) upattern ( 88 ) 8, color : EMPTY_FILL SOLID_FILL LINE_FILL char pattern [ ] = { 0xFF, 0x81, LTSLASH_FILL 3 / / / 0x81, 0x81, 0x81, 0x81, 0x81, 0xFF ; setfillpattern( pattern, BLUE) ; setfillstyle ( ) pattern 11. 2,, setfillpattern( ), setfillstyle( ) SLASH_FILL BKSLASH_FILL LTBKSLASH_FIL HATCH_FILL XHATCH_FILL INTERLEAVE_FILL WIDE_DOT_FILL CLOSE_DOT_FILL USER_FILL / / / \ \ \ \ \ \ USER_FILL, : setfillstyle( HATCH_FILL, YELLOW) ; ( 2) void floodfill( int x, int y, int border) ; border, ( x, y), border ( ), : setcolor( GREEN) ; circle( 80, 60, 30) ; 202
210 11 C floodfill( 80, 63, RED) ; ( 3) : void bar( int left, int top, int right, int bottom) ; void fillpoly( int numpoints, int* polypoints) ; bar( ) rectangle( ),, bar( ), fillpoly( ) drawpoly( ),, fillpoly( ), ( 4) : void fillellipse( int x, int y, int xradius, int yradius ) ; void pieslice( int x, int y, int stangle, int endangle, int radius) ; void sector( int x, int y, int stangle, int endangle, int xradius, int yradius ) ; fillellipse( ) ellipse( ), fillellipse( ), sector( ) fillellipse( ) : fillellipse( ), sector( ), stangle, endangle, sector( ), ellipse( ) pieslice( ) sector( ) : pieslice( ), sector( ) ( xradius yradius sector( ) ), : sector( 120, 120, 90, 180, 30, 40) ; ( 1) viewport,,,, ( 0, 0) void setviewport( int left, int top, int right, int bottom, int clip) ; ( left, top) ( ), ( right, bottom) ( ) clip, clip 0,, ; clip 0,,, : setviewport( 50, 50, 200, 200, 1) ; ( 2) : void outtext( char* textstring) ; void outtextxy( int x, int y, char* textstring) ; void settextstyle( int font, int direction, int charsize) ; 203
211 C outtext( ) textstring, outtextxy( ) ( x, y) textstring settextstyle( ) font TC2. 0, , DEFAULT_FONT 0 88 CHR TRIPLEX_FONT 1, TRIP. CHR SMALL_FONT 2, *. CHR SANS_SERIF_FONT 3 initgraph( ), GOTHIC_FONT 4 direction, : HORIZ_DIR( 0) VERT_DIR( 1) HORIZ_DIR, VERT_DIR charsize, 0 10, 3,, " China", : settextstyle( SMALL_FONT, HORIZ_DIR, 3) ; outtextxy( 20, 20, " China" ) ; TC2. 0,, putpixel( ), ( 3) : void getimage( int left, int top, int right, int bottom, void* bitmap) ; void putimage( int left, int top, void* bitmap, int op) ; unsigned imagesize( int left, int top, int right, int bottom) ; getimage( ) ( left, top), ( right, bottom), bitmap imagesize( ) putimage( ) getimage( ) ( left, top) COPY_PUT 0, bitmap getimage ( ) XOR_PUT 1, op, OR_PUT AND_PUT 3 NOT_PUT 4, : void* buffer; /* * / unsigned s; / * * / s = imagesize( 20, 30, 50, 65) ; / * * / buffer = malloc( s) ; / * * / getimage( 20, 30, 50, 65, buffer) ; / * buffer * / 204 putimage( 100, 100, buffer, COPY_PUT) ; / * * /
212 11 C free( buffer) ; / * * /, : void* buffer; / * * / unsigned s; /* * / s = imagesize( 20, 30, 50, 65) ; / * * / buffer = malloc( s) ; / * * / getimage( 20, 30, 50, 65, buffer) ; / * buffer * / putimage( 100, 100, buffer, COPY_PUT) ; / * * / free( buffer) ; / * * / #include < graphics. h > #include < math. h > #define PI { int gd = VGA, gm = VGAHI; int d, k, x1, y1, x2, y2; int color = 1; double a, e; initgraph( &gd, &gm, " C: \ \ TC" ) ; /* * / d = 100; setcolor( color) ; for ( a = 0; a < = 2* PI; a + = PI /360) { e = d* ( * sin( 4* a) ) ; e = e* ( 1 + sin( 8* a) ) ; x1 = e* cos( a) ; x2 = e* cos( a + PI /8) ; y1 = e* sin( a) /2; y2 = e* sin( a + PI /8) /2; line( x1, y1, x2, y2) ; / * * / color + + ; / * color * / if( color > 15) color = 1; setcolor( color) ; / * * / getch( ) ; / *, * / closegraph( ) ; / * * / #include " graphics. h" #include " dos. h" #include " conio. h" 205
213 C #define XR 30 /* XR * / #define YR 28 / * YR * / #define XMAX 640 / * XMAX * / #define YMAX 480 / * YMAX * / void drawball( int x, int y) ; { int gd = VGA, gm = VGAHI; 206 int x = XR, y = YR; /* x y * / int xincrease = 5, yincrease = 3; / * xincrease yincrease * / initgraph( &gd, &gm, " c: \ \ tc" ) ; / * * / x = 100, y = 100; / * ( x, y) * / while(! bioskey( 1) ) { long i; drawball( x, y) ; / * ( x, y) * / for( i = 0; i < L; i + + ) ; / * * / x + = xincrease; / * x xincrease * / y + = yincrease; / * y yincrease * / if( x > = XMAX - XR x < XR) / * * / { xincrease = - xincrease; / * xincrease, * / x + = xincrease; if( y > = YMAX - YR y < YR) / * * / { yincrease = - yincrease; / * yincrease, * / y + = yincrease; cleardevice( ) ; / * * / closegraph( ) ; / * * / void drawball( int x, int y) / * ( x, y) * / { static int color = 1; int currentcolor; int i; currentcolor = color; color + + ; if( color > 15) color = 1; for( i = 0 ; XR - 3* i > 0 && YR - 3* i > 0 ; i + + ) { setcolor( currentcolor) ; setfillstyle( SOLID_FILL, currentcolor) ; fillellipse( x, y, XR - 3* i, YR - 3* i) ; currentcolor ++ ; if( currentcolor > 15) currentcolor = 1;
214 11 C, drawball( ), color, drawball( ), color,, bioskey( ),, 1, 0, ( cleardevice( ) ),,,, initgraph( ) *. BGI *. BGI C: TC 207
215 A ASCII ASCII ASCII ASCII ASCII NULL SOH STX ETX EOT ENQ ACK BEL BS HT LF VT FF CR SO SI DLE DC1 DC2 DC3 DC4 NAK SYN ETB CAN EM SUB ESC FS GS RS US ( space)! # % & ( ) * +, _. / : ; < = >? A B C D E F G H I J K L M N O P Q R S T U V W X Y Z [ \ ] ^ a b c d e f g h i j k l m n o p q r s t u v w x y z { DEL BEL DLE EM BS DC1 1 SUB NULL HT DC2 2 ESC SOH LF DC3 3 FS STX VT DC4 4 GS ETX FF NAK RS EOT CR SYN US ENQ SO ETB DEL ACK SI CAN 208
216 B C auto break case char const continue default do double else enum estern float for goto if int long register return short signed sizeof static struct switch typedef union unsigned void volatile while C C C, ANSI C, ( 1 ) : #include " math. h" abs int abs( int x) x acos double acos( double x ) arccos( x) x asin double asin( double x ) arcsin( x) x atan double atan( double x ) arctan( x) atan2 double atan2 ( double x, double y) arctan( x/ y) cos double cos( double x) cos( x) x cosh double cosh( double x) x cosh( x) exp double exp( double x) e x fabs double fabs( double x) x floor double floor( double x) x fmod double fmod ( double x, x / y double y) val x frexp double frexp ( double val, 2 n, x int* eptr) val = x* 2 n, n eptr 0. 5x < 1 log double log( double x) ln x log10 double log10( double x) log 10 x 209
217 C modf val double modf ( double val, val, iptr int* iptr) pow double pow ( double x, double y) x y rand int rand( void) sin double sin( double x) sin x x sinh double sinh( double x) x sinh( x) sqrt double sqrt( double x) x x 0 tan double tan( double x) tan( x) x tanh double tanh( double x) x tanh( x) ( 2 ) " ctype. h" isalnum int isalnum( int ch) ch 1, 0 isalpha int isalpha( int ch) ch 1, 0 iscntrl int iscntrl( int ch) ch ( ASI- CII 0 0x1F ) 1, 0 isdigit int isdigit( int ch) ch ( 0-9) 1, 0 ch ( isgraph int isgraph( int ch) ASICII 0x21 0x7F 1, 0 ), islower int islower( int ch) ch ( a - z) 1, 0 ch ( isprint int isprint( int ch) ASICII 0x20 0x7F 1, 0 ), ch ( ispunct int ispunct( int ch) ), 1, 0 isspace int isspace( int ch) ch ( 1, 0 ) isupper int isupper( int ch) ch ( A - Z) 1, 0 isxdigit int isxdigit( int ch) ch 1, 0 ( 0-9 a - f A - F) tolower int tolower( int ch) ch ch toupper int toupper( int ch) ch ch ( 3 ) " string. h" 210
218 strcat strchr strcmp strcpy strlen strstr char * strcat ( char * str1, char* str2) char* strchr( char* str, int ch) int strcmp ( char * str1, char* str2) char * strcpy ( char * str1, char* str2) unsigned int strlen ( char * str) char * strstr ( char * str1, char* str2) str2 str1, str2 \0 str1 str,, ch str1 str2 str2 str1 str1 < str2, str1 = str2 0; str1 > str2 str1 str ( \ 0 ) str2 str1,, ( str2 ) ( 4 ) : #include" stdio. h" clearerr void clearer( FILE* fp) close int close( int fp) 0, ANCI - 1 creat int creat ( char * filename,, ANCI mode int mode) - 1 eof int eof( int fd) 1, ANCI 0 fclose int fclose( FILE* fp) fp 0, 0 feof int feof( FILE* fp), 0 fgetc int fgetc( FILE* fp) fp, EOF fgets fp buf, int* fgets ( char * buf, int ( n - 1 ), n, FILE* fp) buf NULL fopen FILE* fopen( char mode ( * filename, char* mode) filename ), 0 args format fprintf int fprintf( FILE* fp, char * format, args,... ) fp 211
219 C fputc fputs fread fscanf fseek ftell fwrite getc getchar getw open printf putc putchar puts int fputc( char ch, FILE * fp) int fputs ( char * str, FILE * fp) int fread ( char * pt, unsigned size, unsigned n, FILE* fp) int fscanf( FILE * fp, char format, args,... ) int fseek ( FILE * fp, long offset, int base) long ftell( FILE* fp) int fwrite ( char * ptr, unsigned size, unsigned n, FILE* fp) int getc( FILE* fp) int getchar( void) int getw( FILE* fp) int open ( char * filename, int mode) int printf ( char * args,... ) int putc( int ch, FILE * fp) int putchar( char ch) int puts( char* str) format, ch fp ch, str fp, EOF 0,, 0 fp size n, pt fp format 0 args ( args ) fp, base, - 1 offset fp fp ptr n * size fp fp fp, EOF, - 1 ANCI fp, ( ) - 1 ( ) ANCI mode, filename - 1 format args,, ch fp ch,, EOF ch ch,, EOF str, \0, EOF 212
220 putw int putw( int w, FILE * fp) w( ) fp,, EOF ANCI read int read( int fd, char * buf, unsigned count) fd count buf 0-1 ANCI rename int rename ( char * oldname, char* newname) oldname, newname 0-1 fp rewind void rewind( FILE* fp), scanf int scanf ( char * args,... ) format, format, args args, EOF 0 args write int write( int fd, char * buf, unsigned count) buf count fd - 1 ANCI ( 5 ) ANCI C " stdlib. h", C " malloc. h" " stdlib. h" calloc void * calloc ( unsigned n, n,, unsigned size) size 0 free void free( void* p) p malloc void* malloc( unsigned size size), 0 realloc p void* realloc ( void * p, unsigned size) size, size D C, scanf ( ), scanf, & : scanf( " % d% d", x, b) ; 213
221 C,,, scanf C,, scanf : scanf( " % d% d", &x, &b) ; ( TAB ) printf scanf : int x = 1; float a = 2. 5; printf( " x = % f, a = % d \ n", x, a) ;, : X = , y = x, b, : scanf( " % f% d", &x, &b) ; : x b : int n; n = 37750; printf( " n = % d \ n", n) ;, n C, int , 37750,,, long, : 4 long int n n = 37750; printf( " n = % ld \ n", n) ; scanf, : scanf( " % 5. 2f", &m) ; : , n ( printf n ) C : 214 scanf( " % f", &n) ; : { m = 1; / * m n * / n = 2; : printf( " % d, % d \ n", m, n) ; { int b; B = 2; printf( " % d \ n", b) ;
222 C, C, b B, B b, B, : stu: struct stu { char n [ 10] ; float s; ; : stu. s = 67. 5; stu,, : { float x, y; scanf( " % f, % f", &x, &y) ; printf( " The maxmum number is % f", max( x, y) ) ;... float max( float a, float b) { if ( a < b) a = b; return( a) ;, : float max( float a, float b ) ;, C, / *... * / / * < =, > =, =! =, A. C,, : m = 1 n = 0;,, C B., : { if ( x > 0) x + + ; printf( " % d \ n", x) /* * / 215
223 C C., : struct st { char data; int next; / * * / : struct st { char data; ; int next; A., : int max( int x) ; / *, * / {..., B. : if( x > 0) ; x - - ; if( x > 0), ( x > 0),, x 0 x - - ; : for( i = 0; i < 10; i + + ) ; scanf( " % d \ n", &a[ i] ) ; a[ i] 10, for,, a[ i] ( i = 0),,,!, : main ( ) { int x, y, t; scanf( " % d, % d", &x, &y) ; if ( x < y) t = x; x = y; y = t; printf( " The largest number is: % d", x) ; if, ( x > y), x y,, t = x ( x > y), x = y; y = t;, : if ( x < y) {t = x; x = y; y = t;,, C 216
224 10 C,,, : char m; m = " a" ; 2 : m = a ; 11 " = " " == " C, " = ", " == " " = " : int a = 10; if( a = 1) printf( " a = % d", 1) ; else printf( " a! = % d", 1) ; : a = 1, C ( a = 1), 1 a a a 1,, a = 1 if if( a == 1) 12 C,,, : int a( 8) ; / *, C, int a[ 8] ; * / char b[ 5, 2] ; / *, char b[ 5] [ 2] ; * / a( 1) = 3; / *, a[ 1] = 3; * / 13 C, 0, 1 int a[ 5], i; for ( i = 1; i < 6; i + + ) scanf( " % d \ n", &a[ i] ) ; a[ 1] a[ 5 ] 5, a a[ 0] a[ 4], a[ 5], a[ 5] for : for( i = 0; i < 5; i + + ) : int a = 10; printf( " % d \ n", a ++ ) ; printf, 11, 10 a + + a, a 1, + + a a 1, printf, 10 15, : int * p, i = 10; 217
225 C * p = i; / * p, p * / : int a, * p = &a, i = 10; / * p a* / * p = i;,, 16, : char* p, n; * p = &n; p * ; p *, * p p : * p = n; p = &n; 17 : int n = 0, * s = &n; float* q; s = q; s = q : s = ( int* ) q; 18,,, : int n, array[ 5] = {1, 2, 3, 4, 5; for ( n = 0; n < 5; n ++ ) printf( " % d \ n", * array + + ) ; : int n, array[ 5] = {1, 2, 3, 4, 5, * P; p = a; for ( n = 0; n < 5; n ++ ) printf( " % d \ n", * p + + ) ; 19, : f1 ( int a, int b) { c = a; if ( a < b) c = b; return( c) ; 218
226 , : f1( int a, int b) { int c; : { int a = 1, b = 3, f1( int a, int b) ; f1 ( int x, int y) f 1( a, b) ; { x + + ; y + + ; printf(% d, % d \ n, a, b) ; f1 a b 1,, a b 1 C,,, ( ), 21switch : scanf( " % d", &x) ; switch( x) { case 1: printf( " monday" ) ; case 2: printf( " tuseday" ) ; case 3: prlntf( " wednsday" ) ; case 4: printf( " thurthday" ) ; case 5: printf( " friday" ) ; case 6: prlntf( " saturday" ) ; case 7: prlntf( " sunday" ) ; default: prlntf( " error" ) ;, x 5, : friday saturday sunday error case break, case printf break, case, switch break continue continue break : { int n; for ( n = 100; n < 200; n + + ) 219
227 C { if ( n% 3 == 0) break; printf ( " % d \ n", n) ; , break, 3 n continue break 3 n, C,, C,,, 220
新版 明解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
( CIP) /. :, ( ) ISBN TP CIP ( 2005) : : : : * : : 174 ( A ) : : ( 023) : ( 023)
( CIP) /. :, 2005. 2 ( ) ISBN 7-5624-3339-9.......... TP311. 1 CIP ( 2005) 011794 : : : : * : : 174 ( A ) :400030 : ( 023) 65102378 65105781 : ( 023) 65103686 65105565 : http: / /www. cqup. com. cn : fxk@cqup.
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++ 语 言 面 向 对 象 的 重 要 特 征 : 类 和 对 象 抽 象 封 装 继 承 等 主
新・解きながら学ぶ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
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言語入門編『索引』
!... 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
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 ;
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
_汪_文前新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++入門編
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,
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
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++语言 - 运算符、表达式和语句
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
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
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
四川省普通高等学校
四 川 省 普 通 高 等 学 校 计 算 机 应 用 知 识 和 能 力 等 级 考 试 考 试 大 纲 (2013 年 试 行 版 ) 四 川 省 教 育 厅 计 算 机 等 级 考 试 中 心 2013 年 1 月 目 录 一 级 考 试 大 纲 1 二 级 考 试 大 纲 6 程 序 设 计 公 共 基 础 知 识 6 BASIC 语 言 程 序 设 计 (Visual Basic) 9
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
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
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++
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 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,,, ( ),,,,,
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
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
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
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,
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
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) (
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.
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;
Microsoft Word - CPE考生使用手冊160524.docx
大 學 程 式 能 力 檢 定 (CPE) 考 生 使 用 手 冊 2016 年 5 月 24 日 這 份 手 冊 提 供 給 參 加 CPE 檢 定 考 試 的 考 生 內 容 包 含 考 試 環 境 的 使 用, 以 及 解 題 時 所 使 用 I/O 的 基 本 知 識 1. 如 欲 報 名 參 加 CPE 考 試, 請 先 於 CPE 網 站 完 成 帳 號 註 冊, 然 後 再 報 名 該
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
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
Microsoft PowerPoint - OPVB1基本VB.ppt
大 綱 0.VB 能 做 什 麼? CH1 VB 基 本 認 識 1.VB 歷 史 與 版 本 2.VB 環 境 簡 介 3. 即 時 運 算 視 窗 1 0.VB 能 做 什 麼? Visual Basic =>VB=> 程 式 設 計 語 言 => 設 計 程 式 設 計 你 想 要 的 功 能 的 程 式 自 動 化 資 料 庫 計 算 模 擬 遊 戲 網 路 監 控 實 驗 輔 助 自 動
, 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
科学计算的语言-FORTRAN95
科 学 计 算 的 语 言 -FORTRAN95 目 录 第 一 篇 闲 话 第 1 章 目 的 是 计 算 第 2 章 FORTRAN95 如 何 描 述 计 算 第 3 章 FORTRAN 的 编 译 系 统 第 二 篇 计 算 的 叙 述 第 4 章 FORTRAN95 语 言 的 形 貌 第 5 章 准 备 数 据 第 6 章 构 造 数 据 第 7 章 声 明 数 据 第 8 章 构 造
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
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
プログラムの設計と実現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
Microsoft Word - 01.DOC
第 1 章 JavaScript 简 介 JavaScript 是 NetScape 公 司 为 Navigator 浏 览 器 开 发 的, 是 写 在 HTML 文 件 中 的 一 种 脚 本 语 言, 能 实 现 网 页 内 容 的 交 互 显 示 当 用 户 在 客 户 端 显 示 该 网 页 时, 浏 览 器 就 会 执 行 JavaScript 程 序, 用 户 通 过 交 互 式 的
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,
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
概述
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
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
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
全国计算机技术与软件专业技术资格(水平)考试
全 国 计 算 机 技 术 与 软 件 专 业 技 术 资 格 ( 水 平 ) 考 试 2008 年 上 半 年 程 序 员 下 午 试 卷 ( 考 试 时 间 14:00~16:30 共 150 分 钟 ) 试 题 一 ( 共 15 分 ) 阅 读 以 下 说 明 和 流 程 图, 填 补 流 程 图 中 的 空 缺 (1)~(9), 将 解 答 填 入 答 题 纸 的 对 应 栏 内 [ 说 明
目录
ALTERA_CPLD... 3 11SY_03091... 3 12SY_03091...4....5 21 5 22...8 23..10 24..12 25..13..17 3 1EPM7128SLC.......17 3 2EPM7032SLC.......18 33HT46R47......19..20 41..20 42. 43..26..27 5151DEMO I/O...27 52A/D89C51...28
untitled
8086/8088 CIP /. 2004.8 ISBN 7-03-014239-X.... TP313 CIP 2004 086019 16 100717 http://www.sciencep.com * 2004 8 2004 8 1 5 500 787 1092 1/16 16 1/2 391 000 1 2 ii 1 2 CAI CAI 3 To the teacher To the student
<4D F736F F D D342DA57CA7DEA447B14D2DA475B57BBB50BADEB27AC3FEB14DA447B8D5C344>
1. 請 問 誰 提 出 積 體 電 路 (IC) 上 可 容 納 的 電 晶 體 數 目, 約 每 隔 24 個 月 (1975 年 更 改 為 18 個 月 ) 便 會 增 加 一 倍, 效 能 也 將 提 升 一 倍, 也 揭 示 了 資 訊 科 技 進 步 的 速 度? (A) 英 特 爾 (Intel) 公 司 創 始 人 戈 登. 摩 爾 (Gordon Moore) (B) 微 軟 (Microsoft)
Fun Time (1) What happens in memory? 1 i n t i ; 2 s h o r t j ; 3 double k ; 4 char c = a ; 5 i = 3; j = 2; 6 k = i j ; H.-T. Lin (NTU CSIE) Referenc
References (Section 5.2) Hsuan-Tien Lin Deptartment of CSIE, NTU OOP Class, March 15-16, 2010 H.-T. Lin (NTU CSIE) References OOP 03/15-16/2010 0 / 22 Fun Time (1) What happens in memory? 1 i n t i ; 2
(Guangzhou) AIT Co, Ltd V 110V [ ]! 2
(Guangzhou) AIT Co, Ltd 020-84106666 020-84106688 http://wwwlenxcn Xi III Zebra XI III 1 (Guangzhou) AIT Co, Ltd 020-84106666 020-84106688 http://wwwlenxcn 230V 110V [ ]! 2 (Guangzhou) AIT Co, Ltd 020-84106666
Microsoft Word - 97.01.30軟體設計第二部份範例試題_C++_ _1_.doc
電 腦 軟 體 設 計 乙 級 技 術 士 技 能 檢 定 術 科 測 試 範 例 試 題 (C++) 試 題 編 號 :11900-920201-4 審 定 日 期 : 94 年 7 月 1 日 修 訂 日 期 : 96 年 2 月 1 日 97 年 1 月 30 日 ( 第 二 部 份 ) 電 腦 軟 體 設 計 乙 級 技 術 士 技 能 檢 定 術 科 測 試 應 檢 參 考 資 料 壹 試
6020
6020 ... 1 1.1... 1 1.2... 1 1.3 6020... 2 1.3... 5 1.3.1... 5 1.3.2 ISA I/O (S1)... 5 1.3.3 (J4,5,6)... 6 1.3.4... 6... 9 2.1... 9 2.2... 9 2.3 COMPILING AND LINKING... 11 2.3.1 MICROSOFT C MICROSOFT
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,
Microsoft PowerPoint - 20-string-s.pptx
String 1 String/ 1.: char s1[10]; char *s2; char s3[] = "Chan Tai Man"; char s4[20] = "Chan Siu Ming"; char s5[]={'h','e','l','l','o','\0'; 0 1 2 3 4 5 6 7 8 9 10 11 12 s3 C h a n T a i \0 M a n \0 printf
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
SA-DK2-U3Rユーザーズマニュアル
USB3.0 SA-DK2-U3R 2007.0 2 3 4 5 6 7 8 System Info. Manual Rebuild Delete RAID RAID Alarm Rebuild Rate Auto compare Temp Management Load Default Elapse time Event Log 0 2 3 4 2 3 4 ESC 5
2013 C 1 #include <stdio.h> 2 int main(void) 3 { 4 int cases, i; 5 long long a, b; 6 scanf("%d", &cases); 7 for (i = 0; i < cases; i++) 8 { 9 scanf("%
2013 ( 28 ) ( ) 1. C pa.c, pb.c, 2. C++ pa.cpp, pb.cpp Compilation Error long long cin scanf Time Limit Exceeded 1: A 10 B 1 C 1 D 5 E 5 F 1 G II 5 H 30 1 2013 C 1 #include 2 int main(void) 3
提问袁小兵:
C++ 面 试 试 题 汇 总 柯 贤 富 管 理 软 件 需 求 分 析 篇 1. STL 类 模 板 标 准 库 中 容 器 和 算 法 这 部 分 一 般 称 为 标 准 模 板 库 2. 为 什 么 定 义 虚 的 析 构 函 数? 避 免 内 存 问 题, 当 你 可 能 通 过 基 类 指 针 删 除 派 生 类 对 象 时 必 须 保 证 基 类 析 构 函 数 为 虚 函 数 3.
/ / (FC 3)...
Modbus/TCP 1.0 1999 3 29 Andy Swales Schneider [email protected] ... 2 1.... 3 2.... 3 2.1.. 3 2.2..4 2.3..4 2.4... 5 3.... 5 3.1 0... 5 3.2 1... 5 3.3 2... 6 3.4 / /... 7 4.... 7 5.... 8 5.1 0... 9
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
Ps22Pdf
CIP ) / :,2006.2 ISBN 7-80702 - 113-6..........G.206 CIP (2006)080133 :8501168mm 1/ 32 : 120 :2000 2006 3 1 : 5000 ISBN 7-80702 - 113-6/ G206 : 348.00 (16 ) ,?, :,,,,,,,,,!,?,,,,,,?,, ,,,,,,,,,,,,,,,!,!,!
高 职 计 算 机 类 优 秀 教 材 书 目 * 序 号 书 号 (ISBN) 书 名 作 者 定 价 出 版 / 印 刷 日 期 ** 配 套 资 源 页 码 计 算 机 基 础 课 1 978-7-111-30658-0 计 算 机 应 用 基 础 刘 升 贵 29.00 2012 年 8 月
高 职 计 算 机 类 优 秀 教 材 书 目 * 序 号 书 号 (ISBN) 书 名 作 者 定 价 出 版 / 印 刷 日 期 ** 配 套 资 源 页 码 计 算 机 基 础 课 1 978-7-111-30658-0 计 算 机 应 用 基 础 刘 升 贵 29.00 2012 年 8 月 电 子 教 案 P1 2 978-7-111-27081-2 计 算 机 应 用 基 础 ( 第 2
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
(Load Project) (Save Project) (OffLine Mode) (Help) Intel Hex Motor
1 4.1.1.1 (Load) 14 1.1 1 4.1.1.2 (Save) 14 1.1.1 1 4.1.2 (Buffer) 16 1.1.2 1 4.1.3 (Device) 16 1.1.3 1 4.1.3.1 (Select Device) 16 2 4.1.3.2 (Device Info) 16 2.1 2 4.1.3.3 (Adapter) 17 2.1.1 CD-ROM 2 4.1.4
Microsoft Word - 09.數學136-281.docx
136. 計 算 梯 型 面 積 (1 分 ) 請 以 JAVA 運 算 式 計 算 下 面 梯 形 面 積, 並 輸 出 面 積 結 果 梯 形 面 積 公 式 為 :( 上 底 + 下 底 ) 高 2 每 一 組 依 序 分 別 輸 入 梯 形 的 上 底 下 底 及 高 的 整 數 輸 出 梯 形 面 積 輸 入 輸 出 94 190 120 99 54 47 137. 計 算 三 角 形 面
( CIP).:,3.7 ISBN TB CIP (3) ( ) ISBN O78 : 3.
( CIP).:,3.7 ISBN 7 568 383 3.......... TB CIP (3) 334 3 37 ( ) 64536 www.hdlgpress.com.c 7879 6 9.75 479 3 7 3 7 45 ISBN 7 568 383 3O78 : 3. 995,.,.,.,. :,,,,.. :,,,,,,.,,,,.,,. ,,.,,,.,,,.,,,,.,.,,,
TwinCAT 1. TwinCAT TwinCAT PLC PLC IEC TwinCAT TwinCAT Masc
TwinCAT 2001.12.11 TwinCAT 1. TwinCAT... 3 2.... 4... 4...11 3. TwinCAT PLC... 13... 13 PLC IEC 61131-3... 14 4. TwinCAT... 17... 17 5. TwinCAT... 18... 18 6.... 19 Maschine.pro... 19... 27 7.... 31...
序
软 件 工 程 思 想 林 锐 序 软 件 工 程 思 想 讲 述 软 件 开 发 和 做 程 序 员 的 道 理, 视 野 独 特, 构 思 新 颖, 内 容 风 趣, 不 落 窠 臼, 令 人 耳 目 一 新 堪 称 难 得, 以 至 回 味 无 穷 作 者 从 事 了 八 年 的 软 件 开 发 工 作, 在 他 的 博 士 学 位 论 文 完 成 之 际 写 下 了 这 本 心 之 所 感
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
Computer Architecture
ECE 3120 Computer Systems Assembly Programming Manjeera Jeedigunta http://blogs.cae.tntech.edu/msjeedigun21 Email: [email protected] Tel: 931-372-6181, Prescott Hall 120 Prev: Basic computer concepts
<4D6963726F736F667420506F776572506F696E74202D20B5DAD2BBD5C228B4F2D3A1B0E6292E707074205BBCE6C8DDC4A3CABD5D>
Homeworks ( 第 三 版 ):.4 (,, 3).5 (, 3).6. (, 3, 5). (, 4).4.6.7 (,3).9 (, 3, 5) Chapter. Number systems and codes 第 一 章. 数 制 与 编 码 . Overview 概 述 Information is of digital forms in a digital system, and
,768 32,767 32K JMP Jnnn (386+) LOOP CALL [Label:] JMP short/near/far address L10: jmp jmp L20: L10 L20
(Jump) (Loop) (Conditional jump) CMP CALL AND SAR/SHR TEST JMP NOT SAL/SHL Jnnn* OR RCR/ROR LOOP XOR RCL/ROL RETn * nnn, JNE JL -128 127-32,768 32,767 32K JMP Jnnn (386+) LOOP CALL [Label:] JMP short/near/far
IO
1 C/C++ C FILE* fscanf fgets fread fprintf fputs fwrite C++ ifstream ofstream >>
User ID 150 Password - User ID 150 Password Mon- Cam-- Invalid Terminal Mode No User Terminal Mode No User Mon- Cam-- 2
Terminal Mode No User User ID 150 Password - User ID 150 Password Mon- Cam-- Invalid Terminal Mode No User Terminal Mode No User Mon- Cam-- 2 Mon1 Cam-- Mon- Cam-- Prohibited M04 Mon1 Cam03 Mon1 Cam03
ebook14-4
4 TINY LL(1) First F o l l o w t o p - d o w n 3 3. 3 backtracking parser predictive parser recursive-descent parsing L L ( 1 ) LL(1) parsing L L ( 1 ) L L ( 1 ) 1 L 2 L 1 L L ( k ) k L L ( 1 ) F i r s
Chapter 9: Objects and Classes
Fortran Algol Pascal Modula-2 BCPL C Simula SmallTalk C++ Ada Java C# C Fortran 5.1 message A B 5.2 1 class Vehicle subclass Car object mycar public class Vehicle extends Object{ public int WheelNum
