Ps22Pdf



Similar documents
新版 明解C言語入門編

nooog

新・解きながら学ぶC言語

新・明解C言語入門編『索引』

C/C++ - 文件IO

( CIP) /. :, ( ) ISBN TP CIP ( 2005) : : : : * : : 174 ( A ) : : ( 023) : ( 023)

,,,,,,,,,, ( http: \ \ www. ncre. cn,, ) 30,,,,,,,, C : C : : 19 : : : /16 : : 96 : : : ISBN 7

CC213

C/C++程序设计 - 字符串与格式化输入/输出

C/C++ - 函数

C

_汪_文前新ok[3.1].doc

FY.DOC

C/C++语言 - C/C++数据

プログラムの設計と実現II

C/C++ 语言 - 循环

C C


C/C++ - 字符串与字符串函数

Ps22Pdf

CC213

C/C++ - 字符输入输出和字符确认

C 1

untitled

untitled

C

C

untitled

C/C++语言 - 分支结构

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

untitled

Microsoft Word - chap13.doc

C/C++语言 - 运算符、表达式和语句

Microsoft Word - CPE考生使用手冊 docx

Microsoft PowerPoint - 20-string-s.pptx

untitled

untitled

C/C++ - 数组与指针

1 2 / 3 1 A (2-1) (2-2) A4 6 A4 7 A4 8 A4 9 A ( () 4 A4, A4 7 ) 1 (2-1) (2-2) ()

C/C++ - 结构体、共用体、枚举体

4 / ( / / 5 / / ( / 6 ( / / / 3 ( 4 ( ( 2

2015年计算机二级(C语言)模拟试题及答案(四)

新版 明解C++入門編

Microsoft Word - 第3章.doc

上海市本科教学质量年度报告

四川省普通高等学校

内 容 提 要 指 针 持 久 动 态 内 存 分 配 字 符 串 ( 字 符 数 组 ) 2

epub 33-8

tbjx0048ZW.PDF

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("%


CHAPTER VC#

Microsoft Word - 把时间当作朋友(2011第3版)3.0.b.06.doc

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

( ) Wuhan University

( ) : ( ) (CIP) /.. :,003. () ISBN O4 44 CIP (00) : : 7 : 7007 : (09 ) : : :850 mm 68 mm / 3 :0.5 :60 :00 0

第3章.doc


Microsoft Word 年9月二级C真卷.doc

Microsoft PowerPoint - ds-1.ppt [兼容模式]

第5章修改稿

CC213

chap07.key

新・解きながら学ぶJava

碩命題橫式

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

Chapter12 Derived Classes

c_cpp

untitled


3.1 num = 3 ch = 'C' 2

e 2 3 2

高 职 计 算 机 类 优 秀 教 材 书 目 * 序 号 书 号 (ISBN) 书 名 作 者 定 价 出 版 / 印 刷 日 期 ** 配 套 资 源 页 码 计 算 机 基 础 课 计 算 机 应 用 基 础 刘 升 贵 年 8 月

Microsoft Word - 09.數學 docx

Ps22Pdf

C PICC C++ C++ C C #include<pic.h> C static volatile unsigned char 0x01; static volatile unsigned char 0x02; static volatile unsigned cha

高二立體幾何

Ps22Pdf

untitled

Ps22Pdf

Microsoft Word - C-pgm-ws2010.doc

数 学 高 分 的 展 望 一 管 理 类 联 考 分 析 第 一 篇 大 纲 解 析 篇 编 写 : 孙 华 明 1 综 合 能 力 考 试 时 间 :014 年 1 月 4 日 上 午 8:30~11:30 分 值 分 配 : 数 学 :75 分 逻 辑 :60 分 作 文 :65 分 ; 总

科学计算的语言-FORTRAN95


Ps22Pdf

[改訂新版]C言語による標準アルゴリズム事典

tbjx0033ZW.PDF

: : : ( CIP ) : ( ) /. :, ISBN :. G7. 4 CIP ( 00 ) 005 : : ( ) : : ( 0 : 0004) : : : / 6 : 7 ( ) : 408 () : 00

Microsoft Word - 实验习题N.doc


《C语言程序设计》教材习题参考答案

zt

2012年全国计算机等级考试二级C语言考试大纲

Ps22Pdf

( CIP).:,3.7 ISBN TB CIP (3) ( ) ISBN O78 : 3.

桃園縣南美國民小學102學年度學校課程計畫

. (A) (B) (C) A (D) (E). (A)(B)(C)(D)(E) A

untitled

Microsoft Word - 烘焙食品乙級第二部份 doc

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++;

Transcription:

( 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, 70,,,,,,,,, : (B) :,, :, QBASIC, FORTRAN, PASCAL, C, FoxBASE : (A) : ; ( B) : :, 1995, B ( ) 8, 120, 1998, : DOS, Windows ; BASIC QBASIC ;,, ( 98 ) : ( 1 ) :, ( 2) :,, (3 ):

, 500600, ( 98 ) 1999 3

, C C, C C,,, ;, C C,, C,,, 1998 ( C ),, C,, (), C,,,,,, ( ),,,,, C,, ( ) C (, ),, C ( ),,,,, 1999 11

1 C 1 1.1 C 1 1.2 2 1.3 2 3 2 5 2.1 C 5 2.2 5 2.2.1 5 2.2.2 6 2.2.3 6 2.2.4 8 2.2.5 9 2.3 10 2.4 C 11 2.4.1 C 11 2.4.2 C 12 2.4.3 12 2.4.4 12 2.4.5 13 2.4.6 16 2.4.7 17 2.4.8 18 2.4.9 19 2.5 20 21 3 24 3.1 C 24 3.2 25 3.3 25 3.3.1 26 3.3.2 27 3.3.3 30

3.4 33 34 4 39 4.1 if 39 4.1.1 if 39 4.1.2 if 41 4.1.3 if 42 4.2 switch 43 4.3 goto 46 4.4 while do while 46 4.4.1 while 46 4.4.2 do while 47 4.4.3 while do while 47 4.5 for 48 4.6 break continue 51 4.6.1 break 51 4.6.2 continue 51 4.7 52 4.8 53 61 5 68 5.1 68 5.1.1 68 5.1.2 69 5.1.3 71 5.2 71 5.3 79 5.3.1 79 5.3.2 79 5.3.3 80 5.3.4 81 5.3.5 82 5.3.6 85 89 6 95 6.1 95 6.2 96 6.3 97

6.3.1 97 6.3.2 98 6.4 99 6.4.1 99 6.4.2 99 6.4.3 100 6.4.4 102 6.5 104 6.6 107 6.7 109 6.7.1 109 6.7.2 110 6.8 111 6.8.1 111 6.8.2 112 6.8.3 115 6.8.4 115 6.9 116 6.9.1 117 6.9.2 117 117 7 122 7.1 122 7.1.1 122 7.1.2 123 7.2 126 127 8 132 8.1 132 8.2 132 8.2.1 133 8.2.2 133 8.2.3 135 8.3 136 8.3.1 137 8.3.2 137 8.3.3 140 8.3.4 144

8.4 145 8.4.1 145 8.4.2 147 8.4.3 149 8.5 152 8.5.1 152 8.5.2 154 8.6 154 8.7 155 8.7.1 155 8.7.2 156 8.7.3 main 157 158 9 163 9.1 163 9.2 163 9.3 165 9.4 167 9.5 169 9.5.1 169 9.5.2 170 9.5.3 171 9.6 172 9.6.1 172 9.6.2 typedef 173 9.6.3 174 9.7 181 9.7.1 181 9.7.2 182 9.7.3 182 183 10 189 10.1 189 10.2 189 10.3 190 10.4 190 10.5 190 10.6 191

10.7 191 10.8 192 192 11 194 11.1 C 194 11.2 194 11.3 195 11.3.1 ( fopen ) 195 11.3.2 ( fclose ) 196 11.4 196 11.4.1 fputc fgetc ( putc getc ) 196 11.4.2 fputs fgets 198 11.4.3 fread fwrite 199 11.4.4 fprintf fscanf 200 11.5 200 11.5.1 rewind 200 11.5.2 fseek 201 202 206 1 ASCII 206 2 C 207 3 207 4 C 208 5 C 212 6 (C ) 219 7 (C ) 222 8 235 280

1 C 1.1 C C, [1.1] C # include < stdio.h > /, / main ( ) / / { int a,b, c ; / / scanf (% d, % d, & a, &b) ; / a b / c = max ( a, b) ; / max, c / printf ( max = % d, c) ; / c / int max (int x, int y)/ max,,x y, / { int z; / max z, / : if (x > y) z = x; else z = y; return (z) ; / x y z / / z, max / (1 ) C main C C, C, C (2 ) C main, main ( main,, ) (3 ) ( printf scanf ), (1.1 max ) (4 ), include, ( 1.1 )7 (5 ) C, 1.1 1

, (),, ( Link),, 1.1 C 1 1 C 1.2 : (1 ) 1.1 max :,,, main ( ) (2 ) {, {, 1.1 main int a, b, c max int z, a b c z,, C : c = a + b;, 2

1.3 : (1 ), ( 1.1 main max ) (2 ) C,,, (3 ),, if (4 ) / / C, 1.1 A) C B) C main C) C, D) C 1.2 A) B) C) D), 1.3 C A) main B) main C) main D) main 1.4 C A), main B), main C), D) 3

1.5 C, 1 1.6 : 2 3 1.7 4, 5 1.8 C 6 1.9 7, 8 1.10 C 9 1.11 C 10 1.12 C 11 1.13, C, : Very Good 1.14 C, a b c, 4

2 2.1 C C : ( ) C, 2.2.1 2.2,, 12 0-3, 4.6-1.23, a d, : # define PRICE 30 # define PRICE 30, PRICE 30,,,,, ( ),,,, 5

2.2.2, (identifier), C,, : sum, average, class, day, month, student - name, - above, lotus - 1-2 - 3, basic : M.D.John, 123, # 33, 3D64, a > b,, sum SUM,, C ( ), ( IBM PC MS C)8, 8, 8,, : student - name student - number, 8,,,, 2.2.3 1. C : (1 ), 112 0-38 (2 ), 0, 0123 123, 83 (3 ), 0x 0x123 123, 291 2. : int i ; / i / long j, k; / j k / C,, ( word) int, long int, short int Turbo C 2.1 6

2.1 Turbo C int 2-3276832767 - 2 15 - (2 15-1) short[int] 2-3276832767 - 2 15 - (2 15-1) long[int] 4-21474836482147483647 - 2 31 - (2 31-1) unsigned[int] 2 065535 02 16-1 unsigned short 2 065535 02 16-1 unsigned long 4 04294967295 02 32-1 [2.1] { int a, b, c, d; a = 10 ; b = 5 ; c = a + b; d = 32767 + 1 printf( c = % d \ n, c) ; printf( d = % d\ n, d) ; : c = 15 d = - 32768 a b c d, a b 10 5, c a b 15d 32767 1, int, d - 32768, 32768 32767: - 32768: 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0000000 00000000 2.1 2.1 32767, (0, 1 ) 32767 1 15 0, 1, - 32768 ( ),, 7

2.2.4 1., : (1), ( )0.123.123 123.0 123. 0.0 ( 2), 123e3 123E3 12310 3 e(e), e, e3 2.1e3.5.e3 e 2., : float a,b; / a b / double c ; / c / Turbo C, 2.2 2.2 Turbo C float 4 7-10 38 10 38 double 8 1516-10 308 10 308 [2.2] { float x ; double y; x = 123456.7777 ; y = 123456.7777 ; printf( x = % f, y = % f \ n,x, y) ; : x = 123456.781250,y = 123456.777700, x y, 4 8,,,,,,,,, 8

2.2.5 1. : ( ), a? = ;, \ 2.3 2.3 \ n \ t () \ v \ b \ r \ f \ \ \ \ ( ) \ ( ) \ ddd 1 3 8,\ 123, 8 123 \ xhh 1 2 16,\ 21, 16 23,, : char c = \ n ; 2. (), abc \ n a, a,,,, \ 0 ( ASCII 0, ), a, : 3. a \ 0, char : char a,b ; a = O ; b = K ; printf(%c%c \ n, a, b) ; 9

OK, : a = O ; b = K ;, a b, O K2 : (1 ), : char c = A ; (2 ), : char c = \ \ ; printf ( % c, c) ; \ (3 ) ASCII, aascii 97( 1), : char c = 97; printf ( % c, c) ; a, ( ASCII ),, aascii 97, : 01100001, % c, a ( ASCII ) % d (printf(% d, c) ), 97,, [ 2.3] { int a = A, b; char c = 97; b = c - a ; printf ( % d \ n, b) ; 32, AASCII 65, c - a 32 2.3,,, ( ) : i, f float, d double, e long, : 10 + a + i f - d/ e 10

2.2,,,,, short int, float, ( float, double, ) int double, int double, ( double ), 2 2 double,,, int unsigned, long, double int dou ble, int double, int long, int long : 10 + a, a 97, 107; i f, i f double, double ; 107 i f, 107 ( 0, 107.00000 ), double ; e double, d/ e double ; 10 + a+ i f + d/ e, double 2.4.1 C 2.4 C C,, =, C : (1 ) ( + - / % ) (2 ) ( > < = = > = < =! = ) (3 ) (!& & ) (4 ) ( < < > > & ) (5 ) ( = ) (6 ) (? : ) (7 ) (, ) (8 ) ( & ) (9 ) ( sizeof) (10) ( ) (11) (. ) 11

(12) ( [ ] ) (13) ( + + - - ) (14) ( ( ) ) 2.4.2 C C : (1 ), : a = 3 (2 ), :3 + 4 2 (3 ), :5 > 6 (4 ), :3 > 5 & & a > = b (5 ), : a > b? a : b (6 ), : a = 3, b = 4, c = 5 2.4.3, : a + b > c & & c + d < e + (c = f) C C,,, a - b c, b,,,, a - ( b c), : a - b + c, C ( ),,, b, a - b, c,, (, ) : a = b = c = 4 c =, c = 4, c 4,,, 4 b a, C, 3 2.4.4, : + - / % ( ) + + ( )- - ( ) : (1 ), 5/ 2 2,, double 5.0/ 2 2.5 12

(2 ) % ( ),, Turbo C, 15 %4 15 % - 4 3, - 15 %4-15% - 4-3, 15.0 %4 2.4.5 (3 ) + + - -, C, (1 ) =, a = 3( ), 3 a (2 ), : a = 5 :,,a = 5 5( a 5 ), : a = (b = 5) b = 5, 5, a = ( b = 5 ) b = 5 a = b, a 5, 5,, (), C C :,,,,, 0 + 5,, : a = 3 + 5 a,,, 3 + 5, : 3 + 5 = a,, (3 ) =, = + + = : a + = 3 a = a + 3 13

x = y + 8 x = x ( y + 8 ) x% = 3 x = x% 3 a + = 3, a (3 ), a 3, a,x = y + 8x ( y + 8 ), x ( ), C 10, : + =, - =, =,/ =, % =, < < =, > > =, & =,=, = (4 ),, ( ),, i, i = 3.56i 3,,,,, ( signed), ( unsigned),,,, ( ), 51.213468912, 51.21347, (5 ),, a, b, c long, : a = b + (double)c c long double, b : (),, (6 ), + + - - 1 1, : + + i, - - i ( i, i ( )1) i + +, i - - ( i,i ( )1 ), + + i i + + i = i + 1 + + i i + + + + i i = i + 1, i ; i + + i, i = i + 1 : i = 3 ; printf ( % d, + + i) ; 14

4 : printf ( % d, i + + ) ; 3 : ( + + ) ( - - ),,, 5 + + (a + b) + + + + - - - i + +, i,, 3 + +, ( ), - ( i + + ), i 3, printf(%d, - i + + ), i, - i - 3, i 4 (i + + ) i, i 1, 1, - 4, + + - -, i 3, : (i + + ) + (i + + ) + (i + + ) 3 + 4 + 5, 12 Turbo C MS C 9 i 3, i ; i, 9, i 6 : k = ( + + i) + ( + + i) + ( + + i) i, k = 4 + 5 + 6, 15 k = 18, : + + i,, i, i 6, k = 6 + 6 + 6, 18 : i 3, : printf ( % d, % d, i, i + + ),, 3,3, printf (i i + + ), i + + i i + +, i 3 i 1 4, 4 printf i printf 4,3, + + - - : i + +, i, i 1, [ 2.4] (1 ) x + a% 3 (int) ( x + y) %2/ 4 x = 2.5, a = 7, y = 4.7 (2 ) ( float) (a + b)/ 2 + ( int) x% (int) y a = 2, b = 3, x = 3.5, y = 2.3 : ( 1) 2.500000 (2 )3.500000 15

[ 2.5], a = 12 (1 ) a + = a ( 2) a - = 2 (3 ) a = 2 + 3 (4 ) a/ = a + a (5 ) a % = ( n% = 2 ), n 5 ( 6) a + = a - = a = a : ( 1) 24 (2 )10 ( 3) 60 (4 )0 (5 )0 (6 )0 2.4.6 C, : 3 + 5, 6 + 8, : 1, 2 : 1, 2 2, 3 + 5,6 + 8 14, : (a = 3 5, a 4 ), a + 5 a 15, a 4 (a ), a + 5 20, 20 : 1,2,3,,n n 3,,,,, ( for ),, : printf(% d, % d, % d, a,b, c) ; a, b, c, printf, : printf(% d, % d, % d, (a, b, c),b, c) ; ( a, b, c), c,, 16

2.4.7 1. C 6 : < ( ) < = () > ( ) > = () = =! = : () ( ) () () (1 ) 4 ( <, < =, >, > = ),,> = =, > < (2 ) (3 ) 2.3 2 3 2. (C ),, : a > b, a + b > b + c, (a = 3) > ( b = 5), a < b, (a > b) > ( b > c) C,,, 0, 1, 0, 1,, 0, 5 = = 30,5 > = 01 a = 3, b = 2, c = 1, : a > b, 1 (a > b) = = c ( a > b 1, c ), 1 b + c < a, 0 : d = a > b d 1 f = a > b > c f 0( >, a > b 1, 17

:1 > c, 0, f 2.4.8 1. C : (1 ) & & (AND) (2 ) (OR) (3 )! (NOT) & & (), ( ), ( a > b ) & & ( x > y), ( a > b) ( x > y)! ( ),,! ( a > b) 2 4 : a & &b a b,a & &b a b! a a b,a b a,! a, :! a & &b x > y& & c : (1 )! ( )& & () (),! (2 ) & &,!, 2.4 2., C, 1, 0,, 0, 0,, : (1 ) a = 4,! a 0, a 0,,,, 0 (2) a = 4, b = 5, a& & b 1, a b 0,, a& & b, 1 18

,, :, 5 > 3& &2 8 < 4 -! 0 : 5 > 3 ( & & ), 5 3,5 > 31; 1 & & 2, 1 2,, 1; 1 8 < 4 -! 0,! 0 1,, :1 8 < 4-1, 1 8 < 3, < 8 3,8 < 3 0 ( ) 1 0 1, 0 1, 0 0,, 0 0 : c & & d 1( c dascii 0, ),,, : a& & b & &c a (0 ), b b, a b c c a, b c ( ) a, b, c, 2.5 a b c a (0 ), b c; a, b; a b c, 2.6 2 5 2 6 2.4.9, (), C : 1? 2: 3 2.7 19

2 7 : (1 ) : 1, 0 () 2, 2 1 0 (), 3, 3 : max = (a > b)? a :b max, a b max (2 ),, max 2.5 [2.6] x y, : { float x, y, ave ; scanf( % f% f, &x, &y) ; ave = ( x + y)/ 2; printf( ave = % f \ n, ave) ; : 2 5 < > ave = 3.500000,, 3 [2.7] 2 4 3 5, 20

: { int r,h ; float v; r = 2 ; h = 4; v = 3.14 r r h ; printf( r = % d, h = % d, v = % f, r, h,v) ; scanf( % d% d, & r, & h) ; v = 3.14 r r h ; printf( r = % d, h = % d, v = % f, r, h,v) ; : r = 2, h = 4,v = 50.240002 3 5 < > r = 3, h = 5,v = 141.3000 r h, 3.14,, v C, r 2 r r 2.1 A) ABC L10 a - b - a1 B)? 123 printp a + b C) - 12 Zhangp 11F D) Li - Li P for 101 2.2 C, A) B) C) D) 2.3 C A) B) C) 21

D) 2.4 C int short char A) 16 (2 ) B) C) D) 2.5 A) ( ) & & ()! () B)! () ( ) & & () C)! ( ) & & () () D) & & ()! ( ) () 2.6 A) 10 + + b) ( x + y) - - C) + + ( a1 - b2 ) d) ( d + + ) + ( d + + ) + ( d + + ) 2.7 C A) 099-026 0x123 e5 B) 0034 0x102 13e - 3-0.78 C) - 0x22d 06f 8e2.3 e D).e7 0xffff 12% 2.5e1.2 2.8 A) \ n \ \ \ x35 \ B) \ t \ 1010 \ v \ 123 C) \ x110 \ b \ g \ xxx D) \ rr \ r \ 55 \ xff 2.9 A) chr a B) 123 \ C) string S D) 678 \ 0 2.10 A) a = 10 + b - - = 9 + k B) (a = 16 9, b + 5), b - 3 C) a = b - - = c - - D) a = b + 7 = a - b 2.11 a 1, a 2 2.12 32 + A - 2/ 3 5 3, a = b = c = 6 + 2/ 5 4, 22

b = 6, 18 + ( b + = 4 ) 3 5 2.13 a = 3, b = - 4, c = 5,! ( b > c) + ( b! = a) ( a + b) & & ( b - c) 6 2.14 a = 3, b = - 4, c = 5, a + + - c + b + + 7, + + a - c + ( + + b) 8 2.15 a = 3, b = - 4, c = 5, a + b, b 5, a = b + 4 9, b% = c + a - c/ 7 10 2.16 11 { int i, j; float a, b; char c; long m,n ; i = 5 ; j = - 3; a = 25.5 ;b = 3.0 ; m = a/ b; n = m + i/ j ; printf(% d \ n,n) ; 2.17 12 { char ch; ch = B ; printf(%c, % d \ n, ch, ch) ; 2.18 China, :, AE, E A,China Glmre, c1 c2 c3 c4 c5 China,, c1 c2 c3 c4 c5 G lmr e, Glmr e, 23

3 3.1 C C ( ) ( )( ), C : (1 ), C, : if ( )else ( ) for ( ) while ( ) dowhile( ) continue break switch goto return ( ) ( ) ( ) ( ) ( switch ) () ( ) () ( ), :if ( ) else :if( x > y) z = x; else z = y; (2 ), : printf ( This is a C statement. ) ; (3 ) :, : i + + ;, i 1: x + y;, x + y,, x + y, C,,, C ( 24

), C ; (4 ) :,,, (, ) (5 ) {, : { z = x + y; ) t = z/ 100 ; printf(% f, t) ; :, (PASCAL 3.2, C, : (1 ) C =, (2 ) C, : if( (a = b) > 0) t = a ; if a = b, : if ( (a = b; ) > 0) t = a ; if 3.3, C, C, printf scanf, printf scanf,, C, C,, ( printf scanf ),, ( ),, printf scanf 25

3.3.1 1. getchar getchar, : getchar ( ) : (1 ) (2 ), (3 ) getchar,, 2. getche getchar 3. putchar, : putchar (c) ; c, c,, putchar( 97 )a, a ASCII 97putchar ( 10 ) (DOS,, (ASCII 10 ) ) :, ( ) # include < stdio.h > I/ O stdio.h [ 3.1] getchar a b, c1 c2 # include < stdio.h > main ( ) { char c1, c2 ; c1 = getchar( ) ; c2 = getchar( ) ; printf(% c% c \ n, c1, c2 ) ;, ab < >, ab, a < > b < >, c1 a, c2, a, 26

[ 3.2] putchar # include < stdio.h > { char c1, c2, c3,c4, c5, c6, c7; c1 = P ; c2 = u ; c3 = t ; c4 = C ; c5 = h ; c6 = a ; c7 = r ; putchar (c1) ; putchar(c2) ; putchar(c3 ) ; putchar(c4) ; putchar (c5) ; putchar(c6) ; putchar(c7 ) ; : PutChar 3.3.2 1. printf printf printf : printf(, ),, : (1 ), %, % d, % f,, % (2 ),, : printf(% d % d, a,b) ; printf( a = % d ] b = % d, a,b) ; % d,, a b 3 4, : a = 3 ] b = 4 ( ] ), printf 3 4 a b ( 3 4 ), a b a b 12 123, : a = 12 ] b = 123 27

: printf,,, printf( 1, 2, 3,, n) printf 2n 1 2., 3.1 3.1 printf d o x u c s f e g ( ) 8 ( 0) 16 ( 0x) 10,, 6,6 % f % e,0, % ( ), 3.2 3.2 l, d o x u f m( ).n(), n ;, - a, 12478; b, 1274.678, 3.3 3.3 a a b b % d 12478 %f 1274.677979 % 8d ] ] ] 12478 %e 1.274678e + 03 % o 30276 %8.2f ]1274.68 % x 30be % g 1274.68 % u 12478 %10.2e ] ] 1.27e + 03 % - 8d 12478 ] ] ] % - 10.2e 1.27e + 03 ] ] 28

: (1 ) C, % e, 3 ( e + 003), 2 ( e + 03 ) 6, 5 (2 ) long ( d o x u ) l, % ld, % lo, % lx, % lu, l, (3 ) %o, % x,,, a = - 2, 1111111111111110, % o 177776 ( - 2) (4 ) ( int ) %u ;, unsigned %d, unsigned % o % x % u,, a = - 2, %u 65534 (5 ) printf \ n \ t \ b \ r \ f \ 377 (6 ) d o x u c s f e g, % %, 9,, : printf( c = % cf = % 10.3fs = %s, c, f, s) ; % c f, %10.3f, s, %s (7 ) %, %, : printf ( % f% %, 1.0/ 3 ) ; 0.333333% [3.3] # include < stdio.h > { int x1; float x2 ; char c1, c2 ; x1 = 99 ; x2 = 100 ; c1 = a ; c2 = b ; printf( c1 = % c ] c2 = % d ] x1 = % d, x2 = % f, c1, c2, x1, x2 ) ; 29

: c1 = a ] c2 = 98 ] x1 = 99, x2 = 100.000000 c1 c2 ab, c2 d, c2 b, ASCII 3.3.3 scanf 1. scanf scanf(, ) printf,, [3.4] scanf { int a,b, c ; scanf( % d % d% d, &a, &b, & c) ; printf(% d, % d, % d \ n, a,b, c) ; &a& b& c &, & a a scanf : a b c, a b c % d % d% d% d,, tab : 3 ] ] 4 ] ] ] ] 5 < > 3 < > 4 ] 5 < > 3( Tab )4 < > 5 < > % d%d% d,, : 3,4,5 : 3.4 scanf : scanf( % d, % d, % d, & a, &b, &c)? 2. 30 printf, %,,

() 3.4 scanf 3.5 scanf 3.4 scanf d o x c s f e,,, \ 0, f, e f 3.5 scanf l ( %ld, %lo, %lx) double (% lf % le) h ( % hd, % ho, % hx) ( ) ( ) : (1 ) C scanf % u, unsigned, % d %o% x (2 ), : scanf(% 3d% 3d, &a, & b) ; 123456 < >, 123 a, 456 b : scanf(% 3c, & ch), ch, abc, ch a (3 ) %, : scanf(% 2d ] % 3d ] % 2d, &a, &b) ; : 12 ] 345 ] 67 < > 12 a, 67 b, 345,, 31

(4 ), : scanf(% 7.2f, &a) ;, a 12345.67 1234567 < > 3. scanf (1 ) scanf,, a b, : scanf(% d, % d, a,b) ;, a, b& a, & b, C (2 ),, : scanf(% d: % d : % d, &h, & m, & s) ; : 122336 < > : scanf( a = % d, b = % d, c = % d, & a, &b, & c) ; : a = 12,b = 24, c = 36 < >, (3 ) % c, : scanf(%c%c%c, &c1, &c2, &c3) ; : a ] b ] c < > a c1, ] c2, b c3, % c,, ] c2 (4 ), :, ( Tab), %3d, 3 : scanf(% d%c% f, &a, &b, & c) ; : 32

1234 a 123o.26 < > a b c % d 1234 a, 1234,, 1234 aa b, % c, a, c 1230.26123o.26, 123 o,, 123 c [ 3.5] scanf : a = 13,b = 198, c1 = G,c2 = k,x = 2.38, y = - 77.6, z = 132.9 # include < stdio.h > { int a,b; char c1, c2 ; flat x,y, z ; scanf(%3d% 6d%c%c, % f, % f% f% f, & a, % b, % c1, & c2, & x, &y, &z) ; printf(% d, % d, %c, % c, % f, % f, % f \ n, a,b, c1,c2, x, y, z) ; : ] 13 ] ] ] 198 Gk,9.9,2.38-77.6 132.9 < > %3d, 13%6d,, 198 Gk% f, (9.9 )x, y, z : 13,198, G, k,2.38, - 77.6,132.9 3.4 [3.6], : # include < stdio.h > { char c1,c2; cl = getchar( ) ; printf(%c, % d \ n, cl, cl) ; c2 = c1 + 32 ; printf(%c, % d \ n, c2, c2 ) ; : A < > A,65 a,97 33

[ 3.7] a y, : # include < stdio.h > { char ch; ch = getchar( ) + 1-32; putchar (ch) ; : c < > D [ 3.8], (, ) : s = s( s - a) ( s - b) ( s - c) a, b, c, s = a + b + c 2 : # include < math.h > { float a, b, c,s, area ; scanf( % f, % f, % f, & a, &b, & c) ; s = 1.0/ 2 ( a + b + c) ; area = sqrt( s ( s - a) ( s - b) ( s - c) ) ; printf( a = % 7.2f, b = %7.2f, c = % 7.2f, s = % 7.2f \ n, a, b, c, s) ; printf( area = % 7.2f \ n, area) ; : 3,4,6 < > a = 3.00,b = 4.00, c = 6.00, s = 6.50area = 5.33 3.1 : 34 { float y; y = 1678.2431 ;

printf( % - 8.4f \ n, m) ; printf(%10.4f \ n, m) ; A) 1678.3431 B) 1678.2431 C) - 1678.2431 D) 1678.2431 1678.2431 00 1678.2431 001678.2431 1678.2431 3.2 int a = - 2; : printf(%8lx, a) ;, A) % d B) % x, C) % x,, %8lx D) %8lx, 8 3.3 m n (int ), A) getchar( ) B) scanf(% d% 1d, & m, & n) C) putchar (\ ) D) putchar(\ ) 3.4 getchar getche A) getchar, getche B) getche, getchar C) getchar, getche D) getchar, getchar 3.5, 22 o 98 p, { int x1, x2 ; char c1, c2 ; scanf(% d%c% d%c, &x1, &x2, &c1, &c2) ; printf(% d % c % d % c \ n, x1, x2,c1, c2) ; A) 22 o 98 p < > B) 22o 98p < > C) 22o98 p < > D) 22 o98p < > 3.6 { unsigned int l ; l = 65535; printf(% d \ n, l) ; 35

A) - 1 B) 65536 C)1 D) 3.7, 25 ] 13 ] 10 < >, { int x,y, z ; scanf(% d% d% d, &x, &y, & z) ; printf( x + y + z = % d \ n, x + y + z) ; A) x + y + z = 48 B) x + y + z = 35 C) x + z = 35 D) 3.8 : scanf( a = %d, b = % d, c = % d, &a, & b, & c), a 3, b 7, c 5, A) 375 < > B) 3, 7, 5 < > C) a = 3, b = 7, c = 5 < > D) a = 3 b = 7 c = 5 < > 3.9 x y float, A) + + x; B) y = ( x%2 ) / 10; C) x = y + 8; D) x = y = 0; 3.10 { long y = - 12345; printf( y = % - 8ld \ n, y) ; printf( y = % - 08ld \ n,y) ; printf( y = % 08ld \ n,y) ; printf( y = % + 8ld \ n, y) ; A) y = - 12345 B) y = - 12345 C)y = - 12345 D) y = - 12345 y = - 12345 y = 12345 y = - 12345 y = - 0012345 y = - 0012345 y = - 0012345 y = - 0012345 y = 00012345 y = - 12345 y = + - 12345 y = - 12345 y = + 12345 3.11, a 4, c 54.36 36 1, 2 { int a,b;

float c, d, e; scanf( a = % d, c = %f, & a, & c) ; printf( a = % d, c = % f \ n, a, c) ; 3.12 3 { int a = 3, b = 5; float c = 6.5, d = 123.785, e = - 198.34; printf( a = % 5d,b = % - 10d, c = %6.2f,d = % 6.2f, e = % - 10.2f \ n, a,b,c, d, e) ; 3.13, A, 4 # include < stdio.h > { char c; putchar (getchar( ) + 32 ) ; 3.14 5 { int i = 100 ; printf(% d, % o, % x, % u \ n, i, i, i, i) ; 3.15 6 { int i, j; unsigned int u1, u2; u1 = 10000 ;u2 = 40000; i = u1 ; j = u2 ; printf( u1 = % u,u2 = % u \ ni = % d, j = % d \ n, u1, u2, i, j) ; 3.16 % 7, 8 { float f; f = 100.0/ 30; printf(% f% %, f) ; 3.17 9 37

{ short n ; n = - 31; printf(\ ndecimal = % d,hex = % x,octal = % o,unsigned = % u \ n,n, n, n, n) ; 3.18 int a; float b, x; char c1, c2; a = 3, b = 6.5, x = 12.6, c1 = a, c2 = A, scanf 10, 11 3.19 r = 1.5, h = 3, scanf,, 3.20, :, 2 c = 5 9 ( f - 32 ) 3.21, getchar c1 c2, putchar printf 38

4 ( ) if ; switch ; for while do while, continue break 4.1 if if, ( ) 4.1.1 if C if : : if( ) : if( x > y) printf ( % d, x) ; if 4.1( a) : if( ) 1 else 2 : if ( x > y) printf ( % d, x) ; else printf (% d, y) ; 4.1( b) : 4 1 39

if ( 1) 1 else if( 2) 2 else if( 3) 3 else if ( m) m else m + 1 4.2 : 4 2 (1 ) if if,, if(a = = b & & x = = y) printf ( a = b, x = y ) ;,, 0,, 0,, if : if (3 ) printf ( O.K. ) ;, O.K., 3,,, ( ), if : if ( a ) printf (% d, a ) ; : a ASCII 97 (2 ) if, else, : 40

C, if,,, (if else ), if else, if, if (3 ) if else,, { : if (a + b < c & & b + c > a & & c + a > b) { s = 0.5 (a + b + c) ; else area = sqrt( s (s - a) ( s - b) (s - c) ) ; printf( area = % 6.2f, area) ; printf( it is not a trilateral ) ;, {, {, 4.1.2 if if if if, : if ( ) else if ( ) 1 else 2 if if ( ) 3 else 4 if if else if else, if else if if if else : if ( 1 ) if ( 2 ) 1 else if ( 3 ) 2 else 3 4.3 if else,, : if ( ) { if ( ) 1 ( if) 41

4 3 else 2 { if, else if 4.1.3 if [4.1],,, ;, : main ( ) { char ch; scanf (%c, &ch) ; if ( ch > = A& & ch < = Z ) ch = ch + 32 ; printf (%c, ch) ; : A < > a AASCII 65,a ASCII 97 ASCII 32 if if : ch = (ch > = A& & ch < = Z )? (ch + 32) ch; 42 :, if?? [4.2] a b c,

# include < stdio.h > : # include < math.h > { int a,b, c, max; scanf (% d, % d, % d, & a, &b, & c) ; max = a ; if ( abs( max ) < abs( b) ) max = b; / max a,b / if ( abs( max ) < abs(c) ) max = c ; / max a, b, c / printf( max = % d \ n, max) ; : 12, - 34,9 < > max = - 34, : # include < stdio.h > # include < math.h > { int a,b, c, temp, max; scanf( % d, % d, % d, & a, & b, & c) ; temp = (abs(a) > abs (b) )? a : b; max = (abs( temp) > abs(c) )? temp: c; printf( max = % dmax) ; 4.2 switch switch, : switch ( ) { case 1 : 1 : case 2 : 2 case n : n default : n + 1 (1 ) case, case 43

, case, default (2 ) case, (3 ) case (4 ) case, case case, switch, switch,, case, switch, switch, break (5 ) case, : switch( grade) { case A : case B : case C : printf ( > 60 \ n ) ; break; grade A B C [ 4.3], : 3 5/ < >, { float x,y; char o; double r; scanf(%f %f% c, & x, &y, &o) ; switch(o) { case + : r = x + y; break; case - : r = x - y; break; case : r = x y; break; case / : r = x/ y; break; / / printf(% f, r) ; :0.600000 [4.4], A B C D E90 A, 80 89 B, 7079 C,6069 D, 60 E : 44 { int score, temp; char grade ;

scanf ( % d, &score) ; if ( score = = 100) temp = 9; else temp = score/ 10; switch( temp) { case 9 : grade = A ;break; case 8 : grade = B ; break; case 7 : grade = C ;break; case 6 : grade = D ; break; case 5 : case 4 : case 3 : case 2 : case 1 : case 0 : grade = E ; printf( score = % d, grade = %c \ n,score, grade) ; : 90 < > score = 90, grade = A [ 4.5], # include < stdio.h > main( ) { int x = 1, y = 0, a = 0, b = 0; switch( x) { case 1 : / / switch( y) { case 0 : a + + ; break; /, switch / case 1 : b + + ; break ; case 2 : a + + ; b + + ; break; / switch, / printf( a = % d, b = % d, a, b) ; : a = 2, b = 1 switch : break switch 45

4.3 goto goto, : goto ;,,, goto, goto, goto, : (1 ) if ( 2), C break continue goto, goto,, ( ) 10 0 [4.6] if goto, n n = 1 : { int i,sum = 0 ; i = 1; loop: if ( i < = 100) { sum = sum + i ; i + + ; goto loop; printf(% d, sum) ; : 5050 4.4.1 while 4.4 while do while while, : while( ) 46

0, 4.4 :, : (1 ),,, while while (2 ), 4.4.2 do while, : do while( ) ; 4 4 :, :,, ( ),,, 0,, 4.5 4.4.3 while do while while, do while do while while do while while 4.4, 4.4 4.6 ( ), while do while,, while while ( 0 ), 10 [4.7] while do while n n = i (1) ( 2) { int sum = 0, i ; { int sum = 0, i ; scanf (% d, & i) ; scanf(% d, & i) ; while(i < = 10) { sum = sum + i ; { sum = sum + i ; do i + + ; i + + ; 4 5 4 6 while(i < = 10 ) ; printf( % d, sum) ; printf( % d,sum) ; 47

i 10, i > 10,, while, ( i < = 10), do while : while,, ( ) : do while,,,, until ( FORTRAN DO U N TIL), do while,, until() 4.5 for C for,,, while for for( 1; 2;3) : (1 ) 1 (2 ) 2, (0 ),, (3 ) (0 ),, ( 5) (3 ),, 3 (4 ) ( 2) (5 ) for 4.7 for for : for(; ; ) : for (i = 1 ; i < = 100 ; i + + ) sum = sum + i : i = 1 ; while (i < = 100 ) { sum = sum + i ; i + + ; 4 7, for for : 1 ; 48

while( 2) { for 3; : ( 1) for 1, for 1, : for ( ; i < = 100; i + + ) sum = sum + i ;, 1, (2 ) 2,, 2 4.8: for (i = 1 ; ; i + + ) sum = sum + i ; : i = 1 ; while (1 ) { sum = sum + i ; i + + ; 4 8 (3 ) 3, : for ( sum = 0, i = 1; i < = 100 ; ) { sum = sum + i ; i + + ; i + + for 3,,, (4 ) 1 3, 2, : for ( ; i < = 100 ; ) while (i < = 100) { sum = sum + i ; : { sum = sum + i ; i + + ; i + + ;, while for while,,, (5 ), : for ( ; ; ) 49

while (1 ), ( 2 ), (6 ) 1, : for (sum = 0; i < = 100 ; i + + ) sum = sum + i ; 3 1 3,,, : for ( sum = 0, i = 1; i < = 100; i + + ) sum = sum + i; for (i = 0, j = 100 ; i < = j; i + +, j ) k = i + j ; 1 3,,,, 4.9 4 9 4 10,, for (i = 1 ; j < = 100; i + +, i + + ) sum = sum + i; for (i = 1 ; i < = 100; i = i + 2) sum = sum + i ; (7 ) 2 ( i < = 100 ) ( a < b & & x < y),,, : for (i = 0 ; (c = getchar ( ) )! = \ n ; i + = c) ; 50 2 c,

\ n (), \ n, for 4.10,, ASCII, : for, 3, for, 4.6.1 break 4.6 break continue break switch,,, : break; break switch [4.8] { int i,s = 0 ; for(i = 1; i < = 10 ; i + + ) / i > 10 / { s + = i; : s = 1 s = 3 if(s > 5) break ; / s > 5 / printf( s = % d \ n,s ) ; : switch break, 4.6.2 continue : continue;,, [4.9] { int i,n,s ; s = n = 0; 51

for(i = 1; i < = 10 ; i + + ) {if(i% 2 = = 0 ) { s + = i; continue ; / i, n + + ; / n + + ; printf( s = % d, n = % d \ n, s, n) ; : s = 30, n = 5 continue break : continue, break, : ( 1) while( 1) (2 ) while(1) {...... {...... if ( 2) break; if (2) continue ;............ (1 ) 4.11, ( 2) 4.12 4.11 4.12 2 4 11 4 12 4.7,, 52

: (while do while for ), ( 1) while ( ) ( 2) do (3 ) for ( ; ; ) {...... {...... {...... while ( ) do for ( ; ; ) {...... {...... {..... while ( ) ; while ( ) ; ( 4) while ( ) ( 5) for ( ; ; ) ( 6) do {...... {...... {...... do while ( ) for ( ; ; ) {...... {...... {...... while( ) ;............ while ( ) ; 4.8 [ 4.10], 3 4, 3 4, 3 4 : { int number; printf( : ) ; scanf(% d, & number) ; if ( number %3 = = 0 & & number %4 = = 0 ) else printf( 3 4! printf( 3 4! \ n ) ; \ n ) ; : :13 < > 3 4! : :24 < > 3 4! [4.11] : 53

y = - 1 0 1 ( x < 0) ( x = 0) ( x > 0), x, y : { int x, y; scanf(% d, &x) ; if ( x < 0 ) y = - 1 ; else if( x = = 0) y = 0; else y = 1 ; : 3 < > printf( x % d, y % d, x, y) ; x 3,y 1 [ 4.12] year, : year 4, 100, ; year 400, ;, : # include < stdio.h > { int year, leap; : printf( Enter a year: \ n ) ; scanf( % d, &year) ; if(year %4! = 0 ) leap = 0; else if( year% 100! = 0) leap = 1 ; else if( year% 400 = = 0) leap = 1; else leap = 0 ; Enter a year: 37 < > if( leap! = 0 ) printf( % d is a leap year. \ n, year) ; else printf(% d is not a leap year. \ n, year) ; 37 is not a leap year. 54

,, 37 1996 2000 1000 [ 4.13] ax 2 + bx + c = 0, : x1 = - b + b2-4 ac 2 a : b 2, x2 = - b - b2-4 ac, (, a 0) 2 a - 4 ac > 0, x1 x2 ; b 2 b 2-4 ac = 0, x1 x2 ; - 4 ac < 0,, : # include < stdio.h > # include < math.h > { float a, b, c,d, p, r,x1, x2; scanf(%f %f% f, & a, &b, &c) ; d = b b - 4 a c; p = - b/ (2 a) ; if( d > = 0) { r = sqrt( d)/ (2 a) ; x1 = p + r; x2 = p - r; printf( x1 = % f, x2 = % f \ n, x1, x2) ; else printf( \ n ) ; : : 2 5 1 < > x1 = - 0.219224, x2 = - 2.280777 : 1 2 1 < > x1 = - 1.000000, x2 = - 1.000000 : 1 2 3 < > [4.14] 4 1-1 3 + 1 5-1 7 +, 55

10-6 : # include < math.h > { int s; float n, t, pi ; t = 1 ; pi = 0; n = 1.0; s = 1 ; while( (fabs( t) ) > = 1e - 6 ) { pi = pi + t ; n = n + 2 ; s = - s ; / / t = s/ n ; / t / / pi / 4 / pi = pi 4; printf( pi = % 10.6f \ n,pi) ; : pi = 3.141594 [ 4.15] 1!+ 2!+ 3!+ 4!+ + 20! : { float n,s, t ; n = 1 ; s = 0; t = 1; do { t = t n; s = s + t ; n + + ; while( n < = 20) ; printf( 1! + 2! + + 20! = %e \ n,s) ; : 1!+ 2! + + 20!= 2.56133e + 18 [4.16], 1.20,,, 100, : # include < stdio.h > 56

{ int t = 0, m ; float z = 0.0,pj ; for (m = 2; m < = 100 ; ) { z + = 1.20 m ; t + + ; m = 2 pj = z/ t ; printf(% f, pj) ; : 25.199999 [ 4.17],, : # include < stdio.h > { int i ; char number; for ( i = 1; ; i + + ) { scanf(%c, &number) ; if (number = = ) else break; printf( % c,number) ; printf( ) ; : ABC < > ABC for for ( i = 1; ; i + + ), 2 ( ),, if,, [4.18] 100120 3 : { int n; 57

for ( n = 100 ;n < 120 ;n + + ) { if (n %3 = = 0 ) continue ; : printf(% d,n) ; 100 101 103 104 106 107 109 110 112 113 115 116 118 119 n 3, continue,, printf, n 3, printf, [ 4.19], : # include < stdio.h > { char c ; int letter = 0, space = 0,digit = 0, other = 0 ; while ( (c = getchar( ) )! = \ n ) { if(c > = a& & c < = zc > = A& & c < = Z ) let ter + + ; else if(c = = ) space + + ; else if (c > = 0& & c < = 9 ) digit + + ; else other + + ; printf( letter = % d,space = % d,digit = % d,other = % d \ n, letter, space, digit,other) ; : He is 46 years old.< > letter = 12, space = 4, digit = 2,other = 1 58 [4.20]

: { int i, j, k; for ( i = 0; i < = 3; i + + ) { for (j = 0 ; j < = 2 - i ; j + + ) printf( ) ; for ( k = 0; k < = 2 i ;k + + ) printf( ) ; printf(\ n ) ; for ( i = 0; i < = 2 ; i + + ) { for (j = 0 ; j < = i; j + + ) printf ( ) ; for ( k = 0; k < = 4-2 i ; k + + ) printf( ) ; printf ( \ n ) ; [ 4.21],,,153, 153 = 1 3 + 5 3 + 3 3 : { int i, j, k, n; for ( n = 100 ; n < 1000; n + + ) /, n / { i = n/ 100; / / j = n/ 10 - i 10 ; / / k = n% 10 ; / / if(i 100 + j 10 + k = = i i i + j j j + k k k) printf(%5d,n) ; printf(\ n ) ; : 153 370 371 407 [4.22] m n, : { int a,b, num1, num2, temp; scanf(% d% d, &num1, &num2) ; if( num1 < num2) { temp = num1; num1 = num2; num2 = temp; a = num1; b = num2 ; / if a b / 59

while( b! = 0 ) { temp = a% b; a = b; b = temp; / / printf(: % d \ n, a) ; printf(: % d \ n,num1 num2/ a) ; : 12 8 < > :4 :24 [ 4.23], m, m 1 1, m, 2 3 m - 1 m, m, m, m, m, m 2 3, [ m ][ m ] m i > k, 2[ m ],, : # include < stdio.h > # include < math.h > { int i, m, k; printf( Enter m : \ n ) ; scanf(% d, &m) ; k = ( int) sqrt( ( float) m) ; / k = sqrt(m) ; / i = 2 ; while( i < = k & & m% i! = 0) i + + ; / i < k, / if(i > k) printf( % d is a prime number. \ n, m) ; else printf(% d is not a prime number., m) ; : Enter m : 60 17 < > 17 is a prime number. Enter m : 18 < >

18 is not a prime number. [ 4.24] 100200 : # include < math.h > main ( ) { int m, k, i,n = 0 ; for (m = 101 ; m < = 200; m = m + 2 ) { if ( n% 10 = = 0) printf(\ n ) ; : k = sqrt(m) ; for (i = 2; i < = k; i + + ) if ( m%i = = 0) break; if (i > = k + 1 ) { printf(% d, m) ; n = n + 1; 101 103 107 109 113 127 131 137 139 149 151 157 163 167 173 179 181 191 193 197 199 100200, [4.23], for break, [4.23] 4.1 A) 0 1 B) 0 0 C) D) 4.2 char ch A) A < = ch < = ZB) (ch > = A ) & (ch < = Z ) C) ( ch > = A ) & & ( ch < = Z ) D) ( A< = ch) AND ( Z> = ch) 4.3 if A) if ( a1 = = b1 & & c1 = = d1 ) printf( ) ; B) if ( 97 ) printf( ) ; C) if (cx! = cy) {cx - - ; cy + + ; 61

D) if (a > b) printf( % d, &a) else printf(%d, & b) ; 4.4 if, else A) if B) if C) if D) if 4.5 if A) if( a > b ) ; printf(% d %d, a, b) ; else printf(%d % d, a, b) ; B) if(a > b) temp = a; a = b; b = temp; printf(%d % d, a, b) ; else printf(% d % d, a, b) ; C) if( a > b ) { temp = a ; a = b; b = temp; printf(% d %d, a, b) ; ; else printf(% d % d, a, b) ; D) if(a > b) { temp = a; a = b; b = temp; printf(% d % d, a, b) ; else printf(%d % d, a, b) ; 4.6 x1 > x2? x1 : ( x3 > x4? x3: x4 ) x1 = 1, x2 = 3, x3 = 5, x4 = 7 A) 1 B) 3 C) 5 D) 7 4.7 { int x = 2,y = - 1,z = 2; if ( x < y) if (y < 0) z = 0 ; else z + = 1; printf( % d \ n, z) ; A) 3 B) 2 C) 1 D) 0 4.8 62 # include stdio.h { int a,b, d = 241 ;

a = d/ 100 % 9; b = ( - 1) & & ( - 1 ) ; printf( % d, % d, a, b) ; A) 6,1 B) 2,1 C) 6, 0 D) 2, 0 4.9 switch A) case B) case C) default D) break 4.10 class 3, switch ( class) { case 1: printf( First! \ n ) case 2: printf( Second! \ n ) ; case 3: printf( Third! \ n ) ;break; case 4: printf( Fourth \ n ) ; default : printf( Error! \ n ) ; A) Third B) Third Error Four th Error C) Third D) Error 4.11 x = 3; do { y = x - - ; if (! y) { printf( ) ; continue ; printf( # ) ; while(1 < = x < = 2) ; A) # # B) # # C) D) 4.12 while(! a)! a { int a ; scanf( % d, & a) ; while(! a) { printf(o.k. \ n ) ; 63

a =! a ; A) a = = 0 B) a! = 1 C) a! = 0 D) a = = 1 4.13 for ( n = 100 ; n < = 200 ; n + + ) { if( n% 3 = = 0) continue ; printf (%4d,n) ; A) for( n = 100 ; ( n% 3) & & n < = 200; n + + ) printf(%4d, n) ; B) for( n = 100; ( n%3 ) n < = 200; n + + ) printf(%4d, n) ; C) for( n = 100 ; n < = 200; n + + ) if( n% 3! = 0 ) printf(% 4d, n ) ; D) for( n = 100; n < = 200; n + + ) { if( n%3 ) printf(% 4d, n ) ; else con tinue; break; 4.14 C, 1 4.15 year, leap year, : 4, 100 ; 4, 400 () { int year; scanf(% d, &year) ; if( (year % 4 = = printf( leap year ) ; 2 year % 100! = 0) 3 year % 400 = = 0) 4.16 Fibonacci :1,1,2,3,5,8, 40, : F1 = 1 ( n = 1 ) F2 = 1 ( n = 2 ) F = Fn - 1 + Fn - 2 ( n 3) 4 64 { long int f1 = 1, f2 = 1; int i ;

for (i = 1 ; 4 ; i + + ) { printf( % 12ld% 12ld, f1, f2) ; if( 5 ) printf( \ n ) ; f1 = f1 + f2 ; f2 = 6 ; 4.17 7 { int i; for (i = 1; i < 6; i + + ) { if (i % 2) printf( ) ; else continue ; printf(& ) ; 4.18 1234 < >, 8 # include < stdio.h > { int c ; while( (c = getchar( ) )! = \ n ) switch(c - 2 ) { case 0 : case 1 : putchar(c + 4 ) ; case 2 : putchar(c + 4 ) ; break ; case 3 : putchar(c + 3 ) ; case 4 : putchar(c + 2 ) ; break ; printf(\ n ) ; 4.19 9 { int k = 1 ; while( k < = 20) if( + + k% 4! = 2) continue; else printf( % d, k) ; printf(\ n ) ; 4.20 10 65

{ int x = 1, y = 3, z = 5 ; switch( x = = 1) { case 1 : switch (y < 0) { case 1 : printf( A ) ;break; case 2 : printf( B ) ;break; case 0 : switch (z = = 2 x + y) { case 0: printf( C ) ; break; default : printf( F ) ; printf(\ n ) ; case 1: printf( D ) ;break ; default :printf( E ) ;break; 4.21 11 { int a,b ; ; for (a = 0,b = 10; a < b; a + = 2) b = b - 1 ; printf( a = % d, b = % d \ n, a, b) ; 4.22 12 { int x1 = 10, x2 = 5,x3 = 5, x4 = 5 ; int l = 0, m = 0,n = 0 ; for ( ;x1 > x2 ; + + x2 ) l + + ; while(x1 > + + x3 ) m + + ; do n + + ; while( x1 > x4 + + ) ; printf( l = % d, m = % d,n = % d \ n, l, m, n) ; 4.23, 13 ( ), 14 y = - 1 0 1 ( x < 0 ) ( x = 0 ) ( x > 0 ) 66 { int x,y; ( 1) scanf(% d, & x) ;

( 2) y = 0; ( 3) if ( x > = 0 ) ( 4) if ( x > 0 ) y = 1 ; ( 5) else y = - 1 ; ( 6) printf( x = % d, y = % d \ n,x,y) ; 4.24 ( I) 10, 10% ; 10, 20 ( 100000 < I200000), 10 10%, 10, 7.5 % ; 200000 < I400000, 20 ( ), 20 5 % ; 400000 < I600000, 40 3 % ; 600000 < I1000000, 60 1.5% ; I > 1000000, 100 1% I, : if ; switch 4.25,, 4.26,,, ;,,,, 4.27,, 6 1 2 3, 6 = 1 + 2 + 3, 6 1000, 6 its factors are 1,2,3 4.28 : 10 0 k = 1 50 k + k 2 k = 1 1 0 + k = 1 1 k 67

5 5.1.1 : [] ; : int a[10] ; a, 10 : 5.1 [] [] ; : float a[3] [4 ], b[5] [10 ] ; a 34 (3 4 ), b 510 (5 10 ) : float a[3,4],b[ 5,10] ; : (1 ), (2 ),, : int a (10 ) ; (3 ), : int n = 5 ; # define M 5 int a[ n] ; () int a[ M ] ; ( ) (4 ),, int a[10] ; a 10, 0, 10 : a[0 ], a[ 1], a[2 ], a[ 3], a[ 4], a[5 ], a[ 6], a[7 ], a [8 ], a[ 9] int a[3 ] [ 4] ; a 3 4, 0 12 : a[ 0] [0 ], a[0 ] [ 1 ], a[ 0 ] [2 ], a[ 0 ] [ 3], a[ 1 ] [ 0], a [1 ] [ 1 ], a [ 1] [ 2 ], a [ 1] 68

[3 ], a[ 2] [0 ], a[ 2] [1 ], a[ 2] [2 ], a[ 2] [3 ] (5 ) :,, 5.1 a[3 ] [ 4] 5 1 (6 ) C,, : float a[2] [3 ] [4 ] ; :, 5.1.2 1. (1 ) : int a[10] = {0, 1,2,3,4,5,6,7,8,9 ;, a[ 0 ] = 0, a[ 1 ] = 1, a[ 2 ] = 2, a[ 3 ] = 3, a[ 4 ] = 4, a[ 5] = 5, a[ 6] = 6, a[ 7] = 7, a[ 8] = 8, a[ 9] = 9, : int a[ ] = {0,1,2, 3,4,5,6,7, 8,9;, 10, a 10 (2 ) : int a[10] = {0, 1,2,3,4 ; a 10, 5, 5 0, 1, 2, 3, 4, 5 0,, 10 : int a[ ] = {0,1,2,3,4 ; a 5, 10 (3 ) 0, : 69

int a[10] = {0, 0,0,0,0,0,0,0,0,0 ; int a[ 10 ] = {0;,, static(, ), 0: int a[ 10] ; static int b[ 10 ] ; a[ 0] a[ 9], b [0 ] b [9 ]0 2. (1 ) : int a[ 3] [ 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 ;,,,,, (3 ), : int a[ 3] [ 4] = {{1, {5, {9 ; 1, 0 : 1 0 0 0 5 0 0 0 9 0 0 0 : int a[ 3] [ 4] = {{1, {0, 6, {0,0,11; : : 1 0 0 0 0 6 0 0 0 0 11 0 int a[ 3] [ 4] = {{1, {5, 6 ; : 70 1 0 0 0 5 6 0 0 0 0 0 0

(4 ) ( ),, : 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 ;, 12, 4, 3, : int a[ ] [ 4] = {{0,0,3, {, {0, 10;, : 3 : 5.1.3 0 0 3 0 0 0 0 0 0 10 0 0, C : [] : [] [] a[ 2] [3 ] a[ 2-1 ] [ 2 2-1] : a[2, 3], a[ 2-1, 2 2-1 ],, : b[ 1] [2] = a[ 2] [ 3]/ 2, : int a[3 ] [4 ] ; ( ) a[3] [4 ] = 3; ( ) a 34, 02, 03 a[ 3] [4 ] a [ 3 ] [ 4 ] a [ 3 ] [ 4 ] a[ 3] [4 ], a [ 3 ] [ 4 ] 3 4, a[ 3] [4 ] 71

5.2,, [ 5.1] 10, : (1 ) 10, 10 ; (2 ) ; (3 ) ; (4 ) (, ) : { int i, j, t, a[ 10] ; for( i = 0; i < 10 ; i + + ) scanf(% d, &a[i] ) ; for( i = 0; i < 10 ; i + + ) printf(% 4d, a[ i] ) ; printf( \ n ) ; for( i = 9; i > = 0; i - printf( \ n ) ; for(i = 0, j = 9 ; i < j; ) - ) printf( % 4d, a[i] ) ; { t = a[i] ; a[i] = a[j] ; a[j] = t ; i + + ; j - - ; for( i = 0; i < 10 ; i + + ) printf(% 4d, a[ i] ) ; printf( \ n ) ; : 1 2 3 4 5 6 7 8 9 0 < > 1 2 3 4 5 6 7 8 9 0 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1,, : a[0 ] a[ 9 ], a[1 ] a[ 8 ],, i < j [5.2] 10,, : 72 { int i, j, t, a[10 ] = {2,4,1,6,5,9,7,0, 8,3; for(i = 0; i < 10 ; i + + ) printf(% 4d, a[i] ) ; printf(\ ninput t : \ n ) ;

scanf( % d, & t) ; for(i = 0; i < 10 ; i + + ) if( t = = a[i] ) break; for(j = i ; j < 9; j + + ) a[j] = a[j + 1] ; for(i = 0; i < 9; i + + ) printf(%4d, a[i] ) ; printf(\ n ) ; : 2 4 1 6 5 9 7 0 8 3 Input t : 1 < > 2 4 6 5 9 7 0 8 3,,, break,, 0, 7,, a[ 8] a[ 7], a[ 9] a[8 ] 3,, 9 [ 5.3], k,, k = 0, a[ k ] a[ 1], a[1 ] a [ k ], k = 1, k,, k a[0 ] a[ 1], a[ k ] a[2 ], a[2 ] a[ k ], k = 2, k, k a[0 ]a[ 2],, k a[0 ]a[ 9 ] for, a[ 0 ] a[ k], : # define M 10 { int i, j, a[ M ], k, t ; for(i = 0; i < M; i + + ) scanf(% d, &a[i] ) ; for(i = 0; i < M; i + + ) printf(% 4d, a[i] ) ; printf(\ n ) ; k = 0 ; for(j = k + 1 ; j < M ; j + + ) if(a[j] < a[ k] ) k = j ; t = a[0] ; a[0 ] = a[ k] ; a[ k] = t ; for(i = 0; i < M; i + + ) printf(% 4d, a[i] ) ; printf(\ n ) ; : 73

5 3 7 1 0 9 2 8 4 6 < > 5 3 7 1 0 9 2 8 4 6 1 3 7 5 0 9 2 8 4 6 [ 5.4] 10 5.3, k 0, a[ 0]a[9 ] 0,, k i(0i8),, a[i] a[ 9 ] i, i 0 8, i for : main ( ) { int i, j, k, temp, a[10] ; for (i = 0 ; i < 10; i + + ) scanf(% d, &a[i] ) ; for ( i = 0; i < 9 ; i + + ) { k = i ; for (j = k + 1; j < 10 ; j + + ) if(a[j] < a[ k] ) k = j ; temp = a[i] ; a[i] = a[k ] ; a[ k] = temp; for (i = 0 ; i < 10; i + + ) printf(% d, a[i] ) ; printf(\ n ) ; : 5 3 7 1 0 9 2 8 4 6 < > 0 1 2 3 4 5 6 7 8 9 [5.5] 10 ( ) :,, 5.2 6 8 9, 2 3 ( 9 5) 5, 8-5 - 4-2 - 0-9, : 9,, 0 ( 5 ),, 5, 5. 34, 8, 6 5, 5, 4 5 1 n, n - 1 j n - j n = 10, 11, a[ 0], a[ 1] a[ 10 ], 74

5 2 5 3 { int a[11 ] ; int i, j, t ; printf( input 10 numbers: \ n ) ; for ( i = 1; i < 11 ; i + + ) scanf(% d, & a[ i] ) ; printf(\ n ) ; for ( j = 1; j < = 9 ; j + + ) for (i = 1 ; i < = 10 - j ; i + + ) if(a[i] > a[i + 1] ) {t = a[i] ; a[i] = a[i + 1 ] ; a[i + 1] = t ; printf( the sorted numbers : \ n ) ; for ( i = 1; i < 11 ; i + + ) : printf( % d, a[i] ) ; input 10 numbers : 75

1 0 4 8 12 65-76 100-45 123 < > the sor ted numbers: - 76-45 0 1 4 8 12 65 100 123 [ 5.6] a 10, a, : { int i, j, x, a[11] = {1,3,5,7,9,11, 13,15,17,19 ; / / printf( Input x : \ n ) ; scanf(% d, &x) ; for( i = 0 ; i < 10; i + + ) printf( % 4d, a[i] ) ; / / printf(\ n ) ; i = 0 ; / / while( i < 10 & & a[i] < x ) i + + ; / / for( j = 9 ; j > = i ; j - - ) a[j + 1] = a[j] ; / / a[i] = x; / x / for(i = 0; i < 11 ; i + + ) printf(% 4d, a[i] ) ; / / printf(\ n ) ; : Input x: 4 < > 1 3 5 7 9 11 13 15 17 19 1 3 4 5 7 9 11 13 15 17 19 [5.7] : : 76 { int a[2] [3 ] = {{1,2,3, {4, 5,6 ; int b[ 2] [3], i, j; printf( array a : \ n ) ; for (i = 0 ; i < 2 ; i + + ) { for (j = 0; j < 3 ;j + + ) { printf( % 4d, a[i] [j] ) ; b[i] [2 - j] = a[i] [j] ; printf(\ n ) ; a = 1 2 3 4 5 6 b = 3 2 1 6 5 4

printf( array b: \ n ) ; for(i = 0; i < 2; i + + ) { for (j = 0 ; j < 3 ; j + + ) printf(% 4d,b[ i] [ j] ) ; printf( \ n ) ; : array a : 1 1 2 3 4 5 6 array b: 3 2 1 6 5 4 [ 5.8] 1 1 1 2 1 1 3 3 1 1 4 6 4 1 1 5 10 10 5 1 : (1 ) 1; (2 ),, : { int i, j, yh[ 6] [ 6] ; for ( i = 0; i < 6 ; i + + ) { yh[i] [0 ] = 1 ; yh[i] [i] = 1; / 1 / for ( i = 2; i < 6 ; i + + ) for (j = 1 ; j < i ; j + + ) yh[i] [j] = yh[i - 1] [j - 1] + yh [i - 1] [j] ; / / for ( i = 0; i < 6 ; i + + ) { for( j = 0; j < = i; j + + ) printf(% 4d, yh[ i] [ j] ) ; printf(\ n ) ; 77

[ 5.9], 36 5,, : # include < stdio.h > { float a[ 3] [ 6],x,sum ; int i, j; for ( i = 0; i < 3 ; i + + ) for(j = 0 ; j < 5 ; j + + ) { scanf(% f, & x) ; a[i] [j] = x; for (i = 0 ; i < 3; i + + ) { sum = 0 ; for (j = 0; j < 5; j + + ) sum = sum + a[i] [j] ; a[i] [5 ] = sum/ 5 ; for(i = 0 ; i < 3 ; i + + ) { for (j = 0; j < 6 ; j + + ) : printf( % 5.1f, a[i] [j] ) ; printf(\ n ) ; 67 87 67 56 78 < > 98 87 89 67 89 < > 56 76 66 61 52 < > 67.0 87.0 67.0 56.0 78.0 71.0 98.0 87.0 89.0 67.0 89.0 86.0 56.0 76.0 66.0 61.0 52.0 62.2, ( ), ( )sum = 0,,, [5.10] 34,, : 78

{ int i, j, row = 0, colum = 0, max; int a[3] [4 ] = {{1,2,3,4, {9,8,7,6, { - 10, 10, - 5,2 ; max = a[0 ] [ 0] ; for ( i = 0; i < = 2; i + + ) for (j = 0 ; j < = 3 ; j + + ) if ( max < a[i] [j] ) { max = a[i] [j] ; row = i; colum = j ; printf( max = % d, row = % d, colum = % d \ n, max, row, colum) ; : max = 10, row = 2, colum = 1 row colum max, max a[ 0] [0 ], a[0 ] [0 ], row colum 0, max, max row colum, 5.3 5.3.1, : char c[ 10 ] ; c, 10 : c[ 0] = I ; c[ 1] = ; c[2 ] = a ; c[3] = m ; c[4] = ; c[ 5] = h ; c[6 ] = a ; c[ 7] = p ; c[8 ] = p ; c[ 9] = y ; 5.4 c[ 0] c[1 ] c[2] c[ 3] c[ 4] c[5 ] c[6] c[ 7] c[ 8] c[9 ] I a m h a p p y 5.4, : int c[10] ; 79

5.3.2, : (1 ), : char c[ 10 ] = { I, a, m, h, a, p, p, y ; (),,, ( ASCII 0),, : char c[ ] = { I, a, m, h, a, p, p, y ; c 10, : char diamond[5] [5] = {{,,, {,,,, {,,,,, {,,,, {,, ;, 5.5 (2 ) : char c[ ] = { I am happy ;, : char c[ ] = I am happy ;, \ 0, 5 5 char c[ ] = { I, a, m, h, a, p, p, y,\ 0 ; 5.3.3, \ 0\ 0 ASCII 0,, % c \ 0, Hello, 6, : ASCII : H e l l o \ 0 80

72 101 108 108 111 0 6, 5 5.3.4 : : (1 ) % c (2 ) % s, ( string ) char c[ ] = China ; printf(% s, c) ; c 5.6, \ 0 : China : \ 0 C h i n a \ 0 5.6 % s, printf, : printf ( % s, c[ 0] ) ;, \ 0: char c[ 10 ] = { China ; printf ( % s, c) ; China, 10 \ 0, \ 0 : (1 ) % c: scanf (% c% c% c, & c[1 ], &c[2 ], &c[3] ) ; 3 (2 ) %s : scanf (% s, c) ; scanf c,, : 81

char c[ 6] ; : China < > \ 0, 6 scanf, : char str1[ 5],str2 [5], str3[5 ] ; scanf (% s % s% s, str1, str2, str3) ; : How are you? str1 str2 str3 5.7 str1 : str2 : str3 : H o w \ 0 \ 0 a r e \ 0 \ 0 y o u? \ 0 5 7 \ 0 : char str[13] ; scanf (% s, str ) ; 12 : How are you? 12 \ 0 str, How str, How, \ 0, \ 0str 5.8 & H o w \ 0 \ 0 \ 0 \ 0 \ 0 \ 0 \ 0 \ 0 \ 0 \ 0 5 8 : scanf, 5.3.5,, : # include < string.h > 1. puts( ) 82 (\ 0 ) puts

char str[ ] = China \ nbeijing ; puts ( str) ; : China Beijing, 2. gets( ) :,, : gets ( str) : puts gets, : puts ( str1, str2 ) gets( str1, str2 ) 3. strcat( 1, 2), 2 1, 1, 1 ( 8 ) char str1[ 30] = People s Republic of ; : char str2[ ] = China ; printf ( % s, strcat(str1, str2) ) ; People s Republic of China : (1 ) 1, (2 ) \ 0, 1 \ 0, \ 0 4. strcpy( 1, 2), 2 1 : (1 ) 1, 1 2 (2 ) 1(str1 ), 2 83

:,, char str1[ 20] ; char str2[ 20] = China ; strcpy( str1, str2) ; strcpy ( str1, China ) ; (3 ) \ 0 1 (4 ) : str1 = China ; str1 = str2 ; strcpy : char c ; c = a ; 5. strcmp( 1,2) 1 2: strcmp ( str1,str2 ) ; strcmp ( China, Korea ) ; strcmp ( str1, Beijing ) ;, ( ASCII ), \ 0, ;, 1 2, 0 1 2, 1 2, :, : if ( str1 = = str2 ) printf ( yes ) ; : if ( strcmp ( str1,str2 ) = = 0) printf ( yes ) ; 6. strlen( ), \ 0: char str[10] = China ; 84

printf ( % d,strlen( str) ) ; 10, 6, 5, : strlen ( China ) 7. strlwr( ) lwr lowercase ( ) strlwr( ABC )abc 8. strupr( ) upr uppercase ( ) strupr( abc ) ABC, : C, ( ),, 5.3.6 [5.11] : # include < stdio.h > # include < string.h > { int i, j ; char t, ch[ 80] ; gets(ch) ; puts(ch) ; for (i = 0, j = strlen(ch) - 1 ; i < j ; i + +, j - - ) / j / { t = ch[i] ; ch[i] = ch [j] ; ch[j] = t ; puts(ch) ; : asdfgh < > asdfgh hgfdsa [5.12], strlen : 85

# include < stdio.h > { int i = 0 ; char a[ 80 ] ; gets(a) ; puts( a) ; while( a[i]! = \ 0 ) i + + ; /, i 1 / printf(% d \ n, i) ; : asdfgh < > asdfgh 6 [ 5.13], strcat : # include < stdio.h > { char s1 [80 ], s2 [40 ] ; int i = 0,j = 0; printf( \ n Input string1: ) ; scanf(% s, s1) ; printf( \ n Input string2: ) ; scanf(% s, s2) ; while( s1[ i]! = \ 0 ) i + + ; / i 1, / while( s2[ j]! = \ 0 ) s1 [i + + ] = s2[ j + + ] ; / / s1[ i] = \ 0 ; / / printf( \ n New string: % s, s1) ; : Input string1 : country < > Input string2 : side < > New string: country side [5.14], from to strcpy,\ 0 \ 0 : # include < string.h > 86

# include < stdio.h > { char from[80], to[80] ; int i; : printf( Input string: ) ; scanf(% s, from) ; for (i = 0; i < = strlen( from) ; i + + ) / i / to[i] = from[i] ; /, \ 0/ printf( Copied string: % s \ n, to) ; Input string: student < > Copied string: student [ 5.15], s1 s2 strcmp : # include < stdio.h > { int i = 0, a; : char s1 [80 ], s2 [80 ] ; gets( s1) ; gets (s2 ) ; puts( s1 ) ; puts( s2 ) ; while ( s1 [i] = = s2[i] & & s1[i]! = \ 0 ) i + + ; / s1[i]! = \ 0s2 [i]! = \ 0/ a = s1 [i] - s2 [i] ; boy < > if(a > 0 ) printf( ( s1 : % s) > ( s2: % s) \ n, s1,s2) ; if(a = = 0 ) printf( ( s1 : % s) = ( s2: % s) \ n, s1,s2 ) ; if(a < 0 ) printf( ( s1 : % s) < ( s2: % s) \ n, s1,s2) ; girl < > boy girl ( s1 :boy) < ( s2 :girl) [5.16],, : # include < stdio.h > { int i,num, word; 87

char str[ 80 ] ; gets( str) ; num = 0 ; / num, 0 / word = 0; /, / for ( i = 0; str[ i]! = \ 0 ; i + + ) if(str[ i] = = ) word = 0; /,, / else if( word = = 0 ) /, / { num + + ; / word 0, 1 / word = 1 ; / word = 1 / printf( words: % d \ n, num) ; : I am a boy.< > words :4 [ 5.17], : # include < stdio.h > # include < string.h > { int i ; char max[20],str[ 5] [ 20 ] ; / / gets( str[0 ] ) ; /, str[i]i + 1 / strcpy(max, str[0 ] ) ; / max, max / for(i = 1; i < 5; i + + ) { gets (str[ i] ) ; if( strcmp(max, str[i] ) < 0 ) strcpy(max, str [i] ) ; printf( The largest string is \ n% s \ n, max) ; : from < > 88 goto < > get < > girl < > first < > The largest string is goto,

, strcmp strcpy, str[i], 5.1 A) B) C) D) C, 1 5.2 A) int a(5 ) = {1, 2, 3, 4, 5; B) int a[ 5] = {1, 2, 3, 4, 5; C) int a[5 ] = {1-5; D) int a[ 5] = {0,1,2,3,4,5; 5.3 : char x[ ] = 12345 ; char y[ ] = { 1, 2, 3, 4, 5 ; A) x y B) x y C) x y D) 5.4 A) int s[2 ] [ ] = {{2,1,2, {6,3,9 ; B) int s[ ] [ 3] = {9,8,7,6,5,4; C) int s[3 ] [ 4] = {{1, 1, 2, {3, 3, 3, {3, 3, 4, {4, 4, 5; D) int s[ 3, 3] = {{1, {4, {6; 5.5 : char s1[ 80 ], s2 [80] ;,, A) scanf(% s% s, & s1, & s2) ; B) gets( & s1, & s2) ; C) scanf(% s% s, s1, s2 ) ; D) gets(% s%s, s1, s2) ; 5.6 A) if ( strcmp( str1, str2 ) ) printf(% s, str1 ) ; B) if ( str1 > str2 ) printf(%s, str1) ; 89

C) if ( strcmp( str1, str2 ) > 0 ) printf(%s, str1) ; D) if ( strcmp( str1) > strcmp( str2) ) printf(% s, str1) ; 5.7 # include < stdio.h > # include < string.h > { char s1 [80 ] = AB, s2 [80 ] = CDEF ; int i = 0 ; strcat( s1, s2 ) ; while( s1[ i + + ]! = \ 0 ) s2 [i] = s1[ i] ; puts( s2) ; A) CB B) ABCDEF C) AB D) CBCDEF 5.8, : AhaMA Aha < >, # include < stdio.h > { char s[ 80], c = a ; int i = 0 ; scanf( % s, s) ; while( s[i]! = \ 0 ) { if( s[ i] = = c) s [i] = s[i] - 32 ; else if( s[i] = = c - 32 ) s[i] = s [i] + 32; i + + ; puts( s) ; A) ahama B) AhAMa C) AhAMa aha D) ahama aha 5.9 # include < stdio.h > { char a[ ] = morming, t ; int i, j = 0; for(i = 1 ; i < 7 ; i + + ) if(a[j] < a[i] ) j = i ; t = a[j] ; a[j] = a[7] ; a[7 ] = a[ j] ; puts( a) ; A) mogninr B) mo C) morning D) mornin 5.10 s c 1 90

# include < stdio.h > { char s[80 ] ; int i, j; gets( s) ; for ( i = j = 0 ; s[i]! = \ 0 ; i + + ) if( s[i]! = c ) 1 ; s [j] = \ 0 ; puts( s) ; A) s[ j + + ] = s[i] B) s[ + + j] = s[i] C) s[ j] = s[i] ; j + + D) s[ j] = s[i] 5.11 C, 1 5.12 2 # define M 10 { int i; ( 1) int a[ M] = {1,2,3,4,5, 6,7,8; ( 2) for(i = 1 ; i < = M ; i + + ) ( 3) printf(% d, a[i] ) ; 5.13 a a[ 2] [2 ] 3 a[ 4] [5 ] = {{1,2,3, {3,2,1,6, {1 ; 5.14 c 4 char c[ ] = { c language ; 5.15 5 # include < stdio.h > { char c[ 6] ; int i = 0; for ( ; i < 6; c[i] = getchar( ), i + + ) ; for (i = 0 ; i < 6 ;putchar( c[i] ),i + + ) ; : p < > q < > 91

stru < > 5.16 : 9 33,, { int a[3 ] [3 ], sum1 = 0, sum2 = 0 ; / sum1,sum2 / int i, j; for( i = 0; i < 3; i + + ) for( j = 0; j < 3; j + + ) scanf( % d, 6 ) ; for( i = 0; i < 3; i + + ) { sum1 = sum1 + 7 ; sum2 = sum2 + 8 ; printf( sum1 = % d, sum2 = % d \ n, sum1, sum2) ; 5.17 a b { int a[ 2] [3] = {{1,2, 3, {4,5,6; int b[ 3] [ 2], i, j ; printf( array a: \ n ) ; for (i = 0; i < = 1 ; i + + ) { for ( j = 0; 9 ; j + + ) { printf(% 5d, a[ i] [ j] ) ; 10 ; printf(\ n ) ; printf( array b: \ n ) ; for (i = 0 ; 11 ; i + + ) { for (j = 0; j < = 1; j + + ) printf(%5d, b[i] [j] ) ; printf(\ n ) ; 5.18 a, 4, 92 # define N 20 { int a[ N ],i ; for(i = 0 ; i < N ; i + + ) scanf( % d, 12 ) ; for(i = 0 ; i < N; i + + )

{ if( 13 ) 14 ; printf(% 3d, a[i] ) ; printf(\ n ) ; 5.19 15 { int i, f[10] ; f[0 ] = f[ 1] = 1 ; for( i = 2; i < 10 ; i + + ) f[i] = f[i - 2] + f[ i - 1] ; for (i = 0 ; i < 10 ; i + + ) { if(i%4 = = 0) printf(\ n ) ; printf(%3d, f[i] ) ; 5.20 16 { int x,y, i, a[8], j,u, v; scanf(% d, &x) ; / 15 / y = x ; i = 0 ; do { u = y/ 2 ; a[i] = y% 2 ; i + + ;y = u ; while(y > = 1 ) ; for(j = i - 1; j > = 0; j - 5.21 17 { int m = 1,n = 3, j,k = 4 ; int b[5] = {1,3, 5 ; while(m < = n & & k > b[m] ) m + + ; for( j = n - 1 ; j > = m ; j - - ) b[j + 1] = b[ j] ; b[ m] = k ; for (m = 0; m < = n; m + + ) printf( % 3d, b[m] ) ; - ) printf(% d, a[j] ) ; 93

5.22 a, ( ) 5.23 0 19,,, 5.24,, 5.25,,, 5.26,, 5.27, 3, 80 5.28 : 5.29, : AZ az BY by CX cx 26, i (26 - i + 1 ), 94

6 6.1, C, C, [6.1] { int a,b, c ; scanf( % d, % d, & a, & b) ; c = max(a, b) ; printf(max is % d, c) ; max (int x, int y) { int z; z = x > y? x :y; return (z) ; : 7,8 < > max is 8, main, max x y : (1 ),, (2 ) C,, ( ), C, C ( 3) C main, main, main main (4 ),,,, (: main ) 95

(5 ), :,,,,,, (6 ), :,,,,,,, 6.2 (1 ) : { ( ) (2 ) : ( 1, 2, ) { : int max (int x, int y) / / { int z ; / / z = x > y? xy; / / return (z) ; / / (3 ), : ( ) { : 96

void dummy( ) { 6.3 6.3.1,, ( ),, ( ) : (1 ),,, (2 ),, :max (3, a + b), (,, 8 ) (3 ), (4 ),,,, (5 ) C,,,,,,,,,,,, [6.2] a b,, # include < stdio.h > { int a = 1, b = 2, c = 0 ; / a, b, c,1,2,0 / sum(a,b, c) ; /, a,b, c,1,2, 0 / printf( c = % d \ n, c) ;/ c,, z c / sum(int x, int y, int z) / x,y, z, x, y,z 1,2,0 / { z = x + y; / / /,x,y, z / 97

: c = 0,, z 6.3.2,, : (1 ) return return : return ( ) ; return ; return; return return, return, re turn, 6.1 max : max (int x, int y) { return ( x > y? xy) ;, return (2 ), return,,, (3 ),, : int max (float x, int y) char letter (char c1, char c2) double min (int x, int y ) C,, (4 ), return,,, 6.1 max z, max, max float,,, z float, max float (5 ), void ( ): void printstar( ) {,, 98,, void [6.3] 6.2,

# include < stdio.h > { int a = 1, b = 2, c ; / a,b, c, a,b 1,2 / c = sum(a,b) ; /, a,b, c / printf( c = % d \ n, c) ;/ c, c, c / int sum(int x, int y) / x,y 1,2, / { int z; / / z = x + y; return z ; /, x, y, z,z / : c = 3 return,, 6.3 return 6.4 6.4.1 : ( ) ;,,,,, 6.4.2, : 1. : printstar ( ) ;, 2.,, : c = 2 max( a, b) 99

3., : m = max (a, max ( b, c) ) ; max( b, c), max 6.4.3 ( )? (1 ) ( ) (2 ), # include, : # include stdio.h # include < stdio.h >,, : # include math.h # include < math.h > (3 ), ( ),, : ( ) ;, 6.4 [6.4] a b : # include < stdio.h > # include < math.h > / sqrt, / main ( ) { float add( ) ; / / 100 float a, b, c; scanf ( % f% f, & a, &b) ; c = add (a,b) ; printf ( Sum is % f \ n, c) ; float add( float x,float y) / add, float / { double z; z = sqrt( x) + sqrt(y) ; / sqrt( ( double) x) sqrt( ( double)y), sqrt double /

return (z) ; / return ( float)z ;, float / : 3.6 5.5 < > Sum is 4.216037 :float add ( ) ;, add C, : (1 ) ( ),, (2 ),,, (3 ),,, : char letter ( ) ; / 3 / float f( ) ; int i( ) ; main ( ) { / / char letter (char c1, char c2 ) / letter / { float f( float x, float y) / f / { int i(float j, float k) / i / {,, (4 ) ANSI,,, (, ) : : ( 1, 2,, n) ; ( 1 1, 2 2,) ; ( ) 6.4, : float add( float, float) ; 101

float add( float x,float y) ; 6.4, 6.4 add,,,, 6.4.4 [6.5], a b : { int a = 1, b = 2; swap( a, b) ; / a, b / printf( : a = % d, b = % d \ n, a,b) ; / a,b / swap(int a, int b) / a, b,a,b / { int c ; c = a ; a = b; b = c ; / a,b / printf( : a = % d, b = % d \ n, a,b) ; / a,b / /, a,b, c / : : a = 2,b = 1 : a = 1,b = 2, a b :,,, 6.1,,,, a, b 6 1 [6.6] a b c, 4.2, : # include < stdio.h > 102 # include < math.h >