![《程序设计》期末试卷 - 副本_第1页](http://file3.renrendoc.com/fileroot_temp3/2022-5/9/061c04e9-9571-4a18-9ba1-85fb02586d35/061c04e9-9571-4a18-9ba1-85fb02586d351.gif)
![《程序设计》期末试卷 - 副本_第2页](http://file3.renrendoc.com/fileroot_temp3/2022-5/9/061c04e9-9571-4a18-9ba1-85fb02586d35/061c04e9-9571-4a18-9ba1-85fb02586d352.gif)
![《程序设计》期末试卷 - 副本_第3页](http://file3.renrendoc.com/fileroot_temp3/2022-5/9/061c04e9-9571-4a18-9ba1-85fb02586d35/061c04e9-9571-4a18-9ba1-85fb02586d353.gif)
![《程序设计》期末试卷 - 副本_第4页](http://file3.renrendoc.com/fileroot_temp3/2022-5/9/061c04e9-9571-4a18-9ba1-85fb02586d35/061c04e9-9571-4a18-9ba1-85fb02586d354.gif)
![《程序设计》期末试卷 - 副本_第5页](http://file3.renrendoc.com/fileroot_temp3/2022-5/9/061c04e9-9571-4a18-9ba1-85fb02586d35/061c04e9-9571-4a18-9ba1-85fb02586d355.gif)
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、The C Programming Language EXAMINATION PAPERSemester: _ Spring _ Year: _2016_ BEIJING JIAOTONG UNIVERSITY Department: _School of Economics and Management _Class No: _2015_Class 1,2,3 _Student Name: _ _ Student ID: _ _ Important note: your answers must be written
2、60;on the answer sheet Section 1: Fill in the blanks(2 mark for each item, total 30 marks) 1.1 According to the declaration: int a35,the number of elements of
3、 array a is _ _.1.2 Writing conditional expression_ to calculate the value of y. 1 x>0 y= 0 x=0
4、60; -1 x<0 1.3 The value of expression 1<10<5 is _.1.4 The value of expression (10<<1)&4 is_.1.5 The value of expression sizeof(“he
5、llo”) is_.1.6 The output of the following statements is _.int k, s;for(k=1, s=0; k<10; k+) if (k%2=0) continue; s += k; printf("k=%d
6、 s=%d", k, s); 1.7 The output of the following statements is _ #define MM(x,y) (x*y) printf("%d", MM(2+3,15); 1.8 The output of the
7、;following statements is _.int k=1, s=0; switch (k) case 1: s+=10; case 2: s+=20; break; default: s+
8、=3; printf("k=%d s=%d", k, s); 1.9 The output of the following program is _.# include <stdio.h> int f( )
9、; static int k; return +k; void main( ) int k; for(k=0;k<3;k+)
10、 printf("%d#", f( ); 1.10 The output of the following program is _.f (int x) if(x<=1) return 1; else return f(x-1)+f(x-2);
11、0; void main( ) printf("%d", f(4); 1.11 The output of the following statements is _.int k=1, j=2, *p, *q, *t; p=&k; q=&j; t=p; p=q; q=t; p
12、rintf("%d, %d",*p, k); 1.12 The output of the following statements is _.int c =10, 30, 5; int *pc; for(pc=c; pc<c+2; pc+) printf("%d#", *pc); 1.13 The output
13、;of the following statements is _.char *st ="ONE","TWO","FOUR","K" printf("%s, %cn", *(st+2), *st+1); 1.14 The output of the following program is _ &
14、#160;#include <stdio.h> void p(int *x,int y) + *x; y=y+2; void main() var cpro_psid ="u2572954" var cpro_pswidth =966; var cpro_psheight =120;
15、60; int x=0, y=3; p(&y, y); printf("%d, %d", x, y); 1.15 Writing the declaration _ with typ
16、edef, which makes CP a synonym for a character pointer array, 10 elements.1. The value of expression 1+4/5+15<7+4%5+(8,10) is _. 2. The value of expression !10 is
17、;_. 3. The value of expression 3>2>1 is _. 4. The value of expression (-1<<1) is _. 5. The statement for (i=1; i<=9; i+) printf(“%3d”, _);prints out t
18、he following numbers: 1 4 7 10 13 16 19 22 25. 6. According to the declaration: int a10, *p=&a1+2; the last element of array a is p_. 7. Write the
19、 declaration_ with typedef, which makes PA a synonym for a characterpointer array, which contains 100 elements. 8. The following code fragment prints out _. static int
20、60;a34=1,2,3,4,5,6; printf(“%d”,a05); 9. The following code fragment prints out _. char a=“678”,”45”,*p=a+1; printf(“%s,%c”,*p,*p-1); 10. The following code fragment prints out _. int *p,
21、60;*q, k = 1, j=10 p=&j; q = &k p = q (*p)+; printf("%d",k); 11. The following program prints out _. #include <stdio.h> void f(int *x
22、,int *y) int *p; p=x; x=y; y=p; void main() int x=1, y=2; f(&y, &x); printf("%d, %d", x, y); 12. The following program prints out _.
23、#include <stdio.h> #include <string.h> main() char st20=”hello0world!”; printf(“%d,%dn”,strlen(st),sizeof(st); 13. To execute the command: prog 123 456 ABC, the value of *(+arg
24、v2) is_. 14. The following program fragment prints out _. int i; int f(int x) static int k = 0; x+=k+; return x; i=f(2); i=f(3); printf(“%d”,i); 15. The&
25、#160;following program fragment prints out _. int f(int x) return (x>0)? x*f(x-1):3); printf(“%d”,f(f(1); 1. If the variable x is declared correctly, the value of expression (-10<x<0) is_.2. The following code code
26、 fragment will output _.static int x, y, z;z = (x=1) | (y=2);printf("%d ", y);3. The following program will output _.void f( int *pa, int *pb ) int *pt; pt = pa, pa = pb, pb = pt;int main(void) int x=1, y=2; f(&x, &y); printf("%d#%d#", x, y);4. The following code fragment
27、 will output _.int x=3, y=6;x = y = x = y;printf("%d#%d#", x, y);5. The value of expression (double)(10/4) is_.6. The function call encode(“ache”) will output_.void encode( char s ) for( ; *s; s+ ) switch( *s ) case 'a': case 'b': case 'c': case 'd': printf(
28、"%c", 'a'+'d'- *s); break;case 'e': case 'f': case 'g': case 'h': printf("%c", 'e'+'h'- *s); break;default: printf("%c", *s); 7. For the following macro definitions, F0(3+4) will output_.#define F1(var) pri
29、ntf("var = %d", var)#define F0(var) F1(var * var)8. Executing the following command-line program T1: T1 abc bcd cde aed, the output is_.#include <stdio.h>int main(int argc, char* argv) while(*argv+!='a');printf("%s", *argv);return 0;9. For the following recursive fu
30、nction f,function call f(2, '3', '2', '1'); will output_.void f(int n, char a, char b, char c) if(n = 1) printf("%c%c#", a, b) ; else f(n-1, a, c, b); printf("%c%c#", a, b); f(n-1, c, b, a); return;10. Use typedef to define a new type name POINT _and make
31、it denote(表示) a pointer to an array with 10 elements each of which points to a character.11. The following code fragment will output _.char s="Zhejiang"sstrlen(s)/2-1=0;printf("%d#%s#",strlen(s),s);12. The following program will output _.#include <stdio.h>int k;int f(int x)
32、static int k=0;k+; return k+(+x);void main()while (k+-3) printf("%d#",f(k);return;13. After executing the following code fragment, the value of variable z is _.static structint x, y3; a3=0,5,6,7,10,12, *p=a+3;int z;z=*(int *)(p-1)-3);14. Given definition: char *s1; write down an expression
33、 _which is equivalent to ” strlen(s1)=0”. Note: Do NOT use any functions15. The following code fragment will output _struct st int n;struct st *next; a3=1,&a1,3,&a2,5,&a0, *p=&a2;printf("%d",+(p->next->n); 1. What value is stored into the int variable b in each of the
34、 following? Assume that b and n are int variables with b containing 12 and n containing 5. b*=2+3 b=_.b%=(n%=2) b=_.Section 2: Single Choice(2 mark for each item, total 10 marks) 2.1 The precedence of operator _
35、160;is the lowest one.A<< B!= C&& D= 2.2 _ is wrong if it is used as an integer constant.A0xa B010L C10 D1.0 3.3 The expression
36、!(x>0|y>0) is equivalent to _.A!(x>0)&&!(y>0) B!x>0&&!y>0 C!x>0|!y>0 D!(x>0)|!(y>0) 4.4 The value of expression _ isnt 0。 A1/2 B!0 C!EOF DNULL 5.5
37、If x is a float variable, the value of expression (x=10/4) is _ 。 A2.5 B2.0 C3 D2 6.6 If variables are defined and assigned correctly, the expression _ is
38、 wrong.Aa&b Bab C&&x Da, b 7.7 According to the declaration: int a10, *p=a; the expression _ is wrong.Aa9 Bp5 C*p+ Da+ 8.8 _ is wrong.Achar str10; str="string
39、" Bchar str ="string" Cchar *p="string" Dchar *p; p="string" 9.9 If all variables have been defined and declared in the following program, all the var
40、iables which can be used in function fun() are _ #include <stdio.h> void fun(int x) static int y;
41、60; return; int z; void main( ) int a,b; fun(a);
42、60; Ax, y Bx, y, z C a,b,y,z Da,b,x,y,z 10.10 According to the declaration: int p5, *a5; the expression _ is correct.Ap=a Bp0=a C*(a+1)=p Da0=2
43、 1. The precedence(优先级) of operator _is the lowest in the followings.A>=B+C!=D+=2. According to the C syntax, _is the legal character constant in the followings.A"0"B102C12D+=3. The expression _can NOT express the statement ”both x and y are zero”.Ax=0 &
44、& y=0B!x && !yCx=0 | y=0D!(x | y)4. Supposing all the following variables are declared correctly, executing the statement “scanf("%d%c%f", &op1, &op, &op2);”,the values of op1, op and op2 are 1,* and 2.0 each when input_.A1.0*2 B1 * 2 C1.0*2.0D1*25. For the function
45、 declaration void f(char * p),the definition _of var makes the function call f(var) incorrect.Achar var1010;Bchar *var10;Cvoid *var = NULL;Dchar *v=NULL, *var=&v;6. After executing the following code fragment, the value of variable m is _.int m; for( m=0; m<9; m+ ) m+;A8B9C10D117. The stateme
46、nt _of the followings is equivalent to “while( *s+ = *t+ );”.A do *s = *t+; while ( *s+ );B while ( *t ) *s+ = *t+;C do *s+ = *t+; while ( *t );D while ( *s ) *s+ = *t+;8. For definitions: char s23=“ab”, “cd”, *p=(char *)s; the expression _is correct and its value is equivalent to the element s11.A*
47、(s+3)B*s+2Cp11D*+p+29. Given the definitions:#define type1 char *typedef char *type2;type1 s1, s2;type2 s3, s4;All the identifiers of group _are character pointers in the followings.As1, s3Bs1, s2, s3Cs1, s3, s4Ds1, s2, s3, s410. For definition: struct int n; char *str; *p;,the operator “+” will act
48、 on _in the expression “+p->str”.Aponiter strBpointer pCobject which str points toDNone of above1. The precedence of operator _ is the lowest one. A? : B= C+= D& 2. _ is correct if it is
49、160;used as a character constant. A B'080' C'%d' D0xa 3. According to the declaration: char c1=92,c2=92; the value of expression _ is 0. A c1c2 Bc1&c2
50、;Cc2 Dc1|c2 4. According to the declaration: int x=11; the value of expression (x+*1/3) is_. A3 B4 C0 D3.667 5. The value of expression sizeof("num=%dt") is _.&
51、#160;A7 B8 C9 D10 6. In the following assignments or initialization, _ is wrong. Achar s ="hello" Bchar s10; s="hello" Cchar *p="hello" Dchar *p; p=&q
52、uot;hello" 7. The following code fragment prints out _. #define MA(x, y) (x)*(y) int i = 2; i = 3/MA(i, i+2)+5; printf(“%dn”, i); A5 B8 C9 D11 8. static
53、60;struct int x, y3; a3 = 1,2,3,4,5,6,7,8,9,10,11,12, *p; p = a+1; The value of expression *(int *)(p+1)+2) is _. A3 B7 C10 D11 9. After running the fo
54、llowing code fragment, the value of s is _. int i=5, s=0; do if (i%2) continue; else s+=i; while (-i); A15 B9 C6 D5 10. According to the declaration:
55、;int (*p)10, p is a(n) _. Apointer Barray Cfunction Delement of array 1. Determine the output of the following statement: printf("%d", 'M' - 'N');
56、;A) 'M' - 'N' B) M - N B) 3 D) 1 2. Which of following is an illegal user-define symbol? A) scanf B)
57、60;_123 C)C$ D)var 3. Which statement is not a C statement? C) int a; a+; B) z = 20, a += c; C)
58、; D) 4. Which operator can only be applied to integers? A) %= B) / C) = D) <= 5. Determine the output
59、160;of the following program. void main() int y=8,x=7; printf("%d %dn", +x, y+); A) 7,8 B) 9,7 C) 8,8 D) 8,96. C
60、hoose the wrong definition for the character strings. A) char str4= “QUST”; B) char str= “QUST”; C) char *str= “QUST”; D) char str=Q, U, S,
61、;T, 0; 7. Determine the output of the following program. void main() int i, j, m = 0; for(i=1;i<=15;i+=5) for(j=3;j<=19;j+=3)m+; print
62、f("%dn",m); A) 12 B) 15 C) 18 D) 25 8. For the 2-dimensional array int b3=1,0,-1,10,12,8,3,9,0; the value for the b21 is_.
63、60; A) 8 B) 5 C)3 D) 12 9. In the statement while(x), choose the equivalent expression for the x. A)x=0 B)x=1 C)x!=1
64、160; D)x!=0 10. For the following codes: int z=5, *p=&z; the value of the *p is_. A)the address of c B)unknown value C)the address
65、60;of p D)5 11. In order to assign 45 to variant a and assign 64 to variant b with the statement scanf(“%d%d”, &a, &b), which input format
66、 is correct? A) 45 64 B) 45, 64 C) 45;64 D) 4564 12. What is the byte length of the string “tabcd”. A) 6
67、0; B) 7 C) 8 D) 9 13. Determine the output of the value of b. Int a42 = 1,2,3,4,5,6,7,8; b = *(*(a + 2) +
68、60;1); A) 3 B) 4 C) 5 D) 6 14. Determine the output of the following program: main() int n = 8;
69、0;while (n > 5) n-; printf(“%d”, n); A) 876 B) 765 C) 8765 D) 7654 15. What is the functionality of function
70、“rewind”? A) open the file again;B) return the length of the file C) push the pointer to the end of the file D) push the pointer to the beginning of the file( )1Every C+ program consists of at least how many functions? (A) 1 (B)2 (C)3 (D)4( )2Which of the following words is
71、reserved words in C+? (A) abs (B)char (C)str (D)sqrt( )3Assign the value “Ok” to the string variable street. Which of the following statements is valid?(A)street=”Ok”; (B)street=Ok;(C)street=Ok; (D)street Ok; ( )4Which of the following identifiers is invalid?(A) n (B)PAY_DAY (C)6Set (D)num5( )5When
72、the following code is executed, how many iterations of the loop are performed? number = 2; done = false; while (!done) number = number * 2; if (number > 64) done = true; (A)3 (B)4 (C)5 (D)6( )6What is the value of the C+ expression?7 % 2(A)1 (B)2 (C)2.5 (D)3( )7Write a C+ expression for the follo
73、wing algebraic expression. Which of the following expression is valid? 3<y<9 (A)3<y && y<9 (B)3<y | y<9 (C)3<y and y<9 (D)3<y or y<9( )8If a design has one level 0 module and two level 1 modules, how many C+ functions(including main) is the program likely to hav
74、e?(A)1 (B)2 (C)3 (D)4( )9Which of the following function prototypes is valid?(A)int Function(void a); (B)void Function(int a); (C)int Function(a); (D)void int(char a);( )10.What would the heading for a value-returning function named Mul look like if it had two int parameters,num1 and num2, and retur
75、ned a int result?(A) int Mul(int num1,int num2)(B) int Mul(num1,num2);(C) void Mul(int num1,int num2)(D) int Mul(int,int); Section 3: Read each of the following programs and answer questions (5 marks for each item, total
76、 marks: 30) 1.1 The output of the following program is _. #include <stdio.h> void main( ) int k, x, s, t;
77、; x=3; s=0; t=x; for(k=1; k<=3; k+) t=t*
78、10+x; s=s+t; printf("%d#", s); 2.2 When input: 7 3 0 3
79、;0 3 1 2 9 7 6 0<ENTER>, the output is _ #include <stdio.h> void main( ) int j, k, sub, x;
80、160; int a5; for(j=1; j<=2; j+) for(k=0; k<5; k+) &
81、#160; scanf(“%d”, &ak); scanf(“%d”, &x); sub=-1;
82、60; for(k=0; k<5; k+) if(ak=x) sub=k; printf("%d#", sub); 3.3 The ou
83、tput of the following program is _ #include <stdio.h> void main( ) long number, wt, x;
84、 x=number=10230; wt=1; while(x!=0) wt=wt*10; x=
85、x/10; wt=wt/10; while(number!=0) printf("%d#", number/wt);
86、160;number=number%wt; wt=wt/10; 4.4 When input: 3 9 8 6 5 3 7 1 2 4 2 1
87、0;2 3 4<ENTER>, the output is _.#include "stdio.h" void main( ) int flag,i,j,k,col,n,ri,a66; for(ri=1; ri<=2; ri+)
88、160; scanf("%d",&n); for(i=0; i<n; i+) for(j=0; j<n; j+)
89、60; scanf("%d",&aij); flag=0; for(i=0; i<n; i+) &
90、#160; col=0; for(j=0; j<n; j+) if (aicol<aij)
91、60;col=j; for (k=0; k<n; k+) if(aicol<akcol) break;
92、60; if(k>=n) printf("a%d%d=%d#", i, col,aicol); flag=1;
93、60; if(!flag) printf("NO#"); 5.5 When inpu
94、t: how are you? <ENTER>, the output is _.#include <stdio.h> void main( ) int word; char ch;
95、60;word=0; while(ch=getchar()!='?') if(ch=' ') word=0; else if(word=0) word=1; if(ch<='z'&&ch>='a') &
96、#160; ch=ch-'a'+'A' putchar(ch); 6.6 If the following data are stored in text file a.txt one?two?1234?output? And the following
97、;data are stored in text file b.txt one?two?1204?input? The output of the following program is _.# include <stdio.h> # include <stdlib.h> void main() int
98、160;count; char ch1,ch2; FILE *f1, *f2; if (f1 = fopen("a.txt","r") = NULL) printf("Can't open file
99、: %sn", "a.txt"); exit(0); if (f2 = fopen("b.txt","r") = NULL) printf("Can't open file : %sn", "b.txt");
100、160;exit(0); count=0; while (!feof(f1)|!feof(f2) ch1=fgetc(f1); ch2=fgetc(f2);
101、;if(ch1!=ch2) printf("%c#%c#",ch1,ch2); printf("%d#", count); break;
102、 if(ch1='?') count+; fclose(f1); fclose(f2); Section 4: According
103、 to the specification, complete each program (2 mark for each blank, total: 30 marks) 1 If input is n(n>0), calculate the value of s = 1/1! + 1/2! + 1/3! +
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 教育培训机构评估居间合同
- 纺织品交易居间合同协议书
- 2025年度办公室日常保洁与节能照明设备供应服务合同
- 广告投放数据分析合同
- 产品包装设计技术指南
- 安全生产托管协议合同
- 工矿企业产品购销合同
- 厨房承包协议集锦
- 农业质量标准制定指南
- 能源行业能源供应链优化与智能仓储管理
- 西方法律思想史ppt
- 尿路结石腔内碎石患者围手术期并发尿脓毒症护理专家共识
- 交换机工作原理详解(附原理图)
- 小学总复习非连续性文本教学课件
- 2023年考研考博考博英语福建师范大学考试高频考点参考题库带答案
- DLT1123-2023年《火力发电企业生产安全设施配置》
- 世界古代史-对接选择性必修 高考历史一轮复习
- 金锁记优秀课件
- 人教版高中英语必修一单词表(默写版)
- 格式塔心理学与文艺心理学
- 海德堡HRT共焦激光角膜显微镜
评论
0/150
提交评论