《程序设计》期末试卷_第1页
《程序设计》期末试卷_第2页
《程序设计》期末试卷_第3页
《程序设计》期末试卷_第4页
《程序设计》期末试卷_第5页
已阅读5页,还剩19页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

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.3 The value of expression  1<10<5  is _.3. The value of expression 3>2>1 is _.1. The value of expression 1+4/5+15<7+4%5+(8,10) is _. 

4、;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 s=%d",

5、60;k, s); 1.8 The output of the following statements is _.int k=1, s=0; switch (k)        case 1: s+=10;        case 2: s+=20; bre

6、ak;       default: s+=3;   printf("k=%d s=%d", k, s); 1.9 The output of the following program is _.# include <stdio.h>     int f( 

7、;)                          static int k;          return +k;  void main( ) 

8、0; int k;    for(k=0;k<3;k+)       printf("%d", f( );  14. The following program fragment prints out _. int i; int f(int x)  static&

9、#160;int k = 0; x+=k+; return x;  main( )i=f(2); i=f(3); printf(“%d”,i); 1.10 The output of the following program is _.f (int x)  if(x<=1) return 1; else return f

10、(x-1)+f(x-2);  void main( )   printf("%d", f(4);  1. For the following recursive function 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,

11、B; else f(n-1, a, c, b); printf("%c%c", a, b); f(n-1, c, b, a); return;15. The following program fragment prints out _. int f(int x)  return (x>0)? x*f(x-1):3);  printf(“%d”,f(f(1); 5. The sta

12、tement for (i=1; i<=9; i+) printf(“%3d”, _);prints out the following numbers: 1 4 7 10 13 16 19 22 25. 12. The following program prints out _. #include <s

13、tdio.h>#include <string.h> main()  char st20=”hello0world!”; printf(“%dn”,strlen(st); 2. If the variable x is declared correctly, the value of expression (-10<x<0) is_.3. The following code fragment will output _.static int x, y, z;z = (x=1) | (y=2);

14、printf("%d ", y);4. The value of expression (double)(10/4) is_.5. The following code fragment will output _.char s="WEIHAI"sstrlen(s)/2-1=0;printf("%dn%s#",strlen(s),s);6. The following program will output _.#include <stdio.h>int k;int f(int x)static int k=0;k+; r

15、eturn k+(+x);void main()while (k+-3) printf("%dn",f(k);return;1. What value is stored into the int variable b in each of the 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=_.5.  After running the pro

16、gram below , if the output (z) is 9.00,please predict the initial value of x. main()   int a=7, b=2; float x= _ , y=1.1,z; z=a/2+b*x/y+1/2; printf("%.2fn",

17、 z );  Predict what gets printed: _          . main()    int x; for (x=1; x<10; x+)   if  (x<3)  continue; x*=2

18、60; printf(“#”);   9. Predict what gets printed: _          .    void fun()     static int a=1;      a*=a+1; p

19、rintf(“%d,”,a);        main()      int cc;      for(cc=1;cc<4;cc+) fun();    10. Predict what gets printed:_. main()  int array

20、  = 2, 8, 3, 11, 13, 2, 8, 2;  int k;   int total = 0;  for ( k = 0; k < 8; k+ )    if ( array k % 2)&

21、#160;break;   total += array k;    printf ( “%d ”, total ); Section 2: Single Choice(2 mark for each item, total 10 marks) 1. Determine the output

22、0;of the following statement:  printf("%d", 'M' - 'N'); A'M' - 'N'   BM - N B3     D1 2. Which of following is an 

23、;illegal user-define symbol? Ascanf      B_123   C)C$       D)var 2.1 The precedence of operator  _  is the lowest one.A, B!= C&&

24、60;D= 1.   The precedence(优先级) of operator _is the lowest in the followings.A>=B+C,D+=2.2 _ is wrong if it is used as an integer constant.A0xa     B010L   C10  D1.0 2. According to t

25、he C syntax, _is the legal character constant in the followings.AnB18CDxab2. _ is correct if it is used as a character constant. A B'080' C'%d' D0xa 3. The expression _can NOT express the statement ”both

26、x and y are zero”.Ax=0 && y=0B!x && !yCx=0 | y=0D!(x | y)12. What is the byte length of the string “tabcd”.  A6          B7  C8      D9 2.3

27、 The expression  !(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) 2.5 If x is a float variable,  the value 

28、of expression (x=10/4) is _ 。 A2.5 B2.0 C3 D2 4. The value of 10/9 is D A. 1.1                      

29、            B. 1.111 C. 1.1111                               D. 1

30、8. Assuming x = 10, the expression: x += 15*6 changes the value of x to B A. 150                     

31、0;            B. 100 C. 900                                 

32、 D. 90 9. Assuming x is 10, what is the output: printf(“%d”,+x); D A. 8                         

33、0;          B. 9 C. 10                                   D.&

34、#160;113. The statement _ is correct if a is an integer variable and b is a double precision float variable . Ascanf(“%d,%f”, &a, &b); Bscanf(“a=%d b=%*f”, &a, &b); Cscanf(“%d%*lf”, &a, &b); Dscanf(“%d%*lf”, &a );3. According to the declaration: c

35、har c1=92,c2=92; the value of expression _ is 0. A c1c2 Bc1&c2 Cc2 Dc1|c2 4. According to the declaration: int x=11; the value of expression (x+*1/3) is_. A3

36、0;B4 C0 D3.667 5. The value of expression sizeof("num=%dt") is _. A7 B8 C9 D10 2. Just find the result of this following program #include stdio.hmain() double d=3.2; int x,y; x=1.2; y=(x+3.8)/5.0; printf("%d n&

37、quot;, d*y);A) 3 B)3.2 C)0 D)3.077. 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 4. Su

38、pposing 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*211. In order to assign 45 to varia

39、nt a and assign 64 to variant b with the statement scanf (“%d%d”, &a, &b), which input format is correct? A45 64      B45, 64 C45;64   &#

40、160; D4564 8. For the 2-dimensional array int b3=1,0,-1,10,12,8,3,9,0; the value for the b21 is_. A) 8B) 5C)3D) 125. After executing the following code fragment, the value of variable m is _.int m; for( m=0; m<9; m+ ) m+;A8B9C10D11 14. Determine the output of

41、60;the following program: main()    int n = 8;  while (n > 5)     n-;   printf(“%d”, n);   A876   B765   C8765  D7654 

42、;5. Just find the result of this following program #include stdio.hmain( )int n=4;while(n-)printf("%d ",-n);A) 2 0 B) 3 1 C) 3 2 1 D) 2 1 09. After running the following code fragment, the value of s is _. 

43、;int i=5, s=0;  do if (i%2) continue; else s+=i; while (-i); A15 B9 C6 D5 19. What is the main problem with the following?_   main( )    

44、60; int a10,i;   for (i=0;i<10;i+)    scanf (“%d”,ai);   for (i=0;i<10;i+)     ai= ai+1;   A) Nothing is wrong. B) Line is wrong. C)&#

45、160;Line is wrong. D) Both line and   are wrong.18. Predict the output from: _ if (5 < 4)  if (6 > 5)  putchar('1');  else if (4 &g

46、t; 3) putchar('2');  else putchar('3'); putchar('4');  A) 4  B) 2  C) 24  D) 4 or 24, depending upon the implementation.10 As we know th

47、at a library function double acos(double x)  )1,1(-Îx which  is included in “math.h”.  which one of the following works properly?_ A #include “stdio.h”   i

48、nt y=acos(2);  B #inlcude “math.h”   int z;    z=acos(0.5);  C #include “math.h”   double y,x;  y=acos(x); D #include “math.h”   int x,z;  z

49、=acos(x=0.3);18.If strcopy is used in the program,what kind of file shall be included?A)stdio.h B)string,h C)math.h D)string.h3. What does strcat (an_array, “this”); do?_ A)       finds “this” in an_array B)

50、60;      adds “this” to the end of an_array C)       compares an_array and “this” D)    copies “this” into an _array8. Assuming th

51、at  the value of grade  is C, predict what gets printed_.switch(grade)   caseA:printf(“*”);    caseB:printf(“*”);    caseC:printf(“*”);     caseD:printf(“*”); &

52、#160;   default   :printf(“#”);   A)       *    B)      *   C)       *#   D)  *#16.The running result of  foll

53、owing program is( ).#include<stdio.h>main()int a=1;switch(a) case 0: printf("() ");case 1: printf("(*>_<*)");case 2: printf(" (_) ");break; default: printf("(*_*) ");printf("%d",a);A)(*>_<*)(_)1B)()(*>_<*)1C)(*>_<*) (_)

54、(*_*)1D) (_) (*>_<*)120. The program segment (程序段) below reverses(逆序) the string s in the place, which one is written correctly?_A)for (i = 0, j = strlen(s); i < 

55、;j; i+, j-) c = si, si = sj, sj = c; B)  for (i = 0, j = strlen(s)-1; i < j; i+, j-)  c = si, si = sj, sj = c; C) for

56、 (i = 0, j = strlen(s)-1; i < j; i+, j-)  c = si;  si = sj;  sj = c; D)  for (i = 0, j = strlen(s); i < j; i+, j-)

57、    c = si;  si = sj;  sj = c; 2.7 According to the declaration: int a10, *p=a; the expression _ is wrong.Aa9 Ba+ Cp5 D*p+2.8 _ is wrong.Achar *p

58、="string"Bchar str ="string" Cchar str10; str="string"  Dchar *p; p="string" 2.10 According to the declaration: int p5, *a5; the expression _ is correct.Ap

59、=a Bp0=a  C*(a+1)=p  Da0=2 The value of expression *(int *)(p+1)+2) is _. A3  B7 C10 D11 13. Determine the output of the value of b.Int a42 = 1,2,3,4,5,6,7,8;b = *(*(a + 2) + 1);A) 3B) 4C) 5 D) 615. What&#

60、160;is the functionality of function “rewind”? Aopen the file again;Breturn the length of the file Cpush the pointer to the end of the file Dpush the pointer to the beginning of the file6. In the following assignments or init

61、ialization, _ is wrong. Achar s ="hello" Bchar s10; s="hello" Cchar *p="hello" Dchar *p; p="hello" 20.which one statement is correctA)char s23=“xy”;B)char s14=“abcd”;C)char s33=a,x,y;D)

62、char s423=“xyz”,“abc”;2.11 For definition: struct int n; char *str; *p;,the operator “+” will act on _in the expression “str=+p”.Aponiter strBpointer p Cobject which str points to DNone of above16.The running result of  following program is( ).include “stdio.h”main() struct person char name30;

63、char gender; int age; student;A)30 B)32 C)33 D)34When the file is closed successfully, the return value of function fclose is ( )A )-1 B) TURE C) 0 D )12.9 If all variables have been defined and declared in the following program, all t

64、he variables which can be used in function fun() are _  #include <stdio.h>     void fun(int x)   static int y;          

65、0;     return;          int z; void main( )       int a,b;         fun(a);       

66、0;       Ax, y Bx, y, z C a,b,y,z Da,b,x,y,z 3. Which statement is not a C statement? C int a; a+;  B x+y = 20; C    

67、60;D   4. Which operator can only be applied to integers?    A%=   B/   C=   D<= 5. Determine the output of the following program. v

68、oid main()   int y=8,x=7;   printf("%d %dn", +x, y+);   A7,8   B9,7   C8,8   D8,96. Choose the wrong definition for the character strin

69、gs.   Achar str4= “QUST”;  Bchar str= “QUST”; Cchar str8= “QUST”;    Dchar str2=Q, U,S, T ; 8. For the 2-dimensional array int b3=1,0,-1,10,12,8,3,9,0; the value

70、0;for the b21 is_.     A8   B5   C)3   D12 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+; 

71、printf("%dn",m);  A12   B15   C18   D25 9. In the statement while(x), choose the equivalent expression for the x.A)x=0 B)x=1 C)x!=1 D)x!=03. Just find the result of this following program #include stdio.h void fun1(int n,int a 3)

72、for(int I=0;In;I+) for(int j=0;jn;j+) aIj=aIj/aII; int main() int a33=6,4,2,8,6,4,9,6,3; fun1(3,a); for(int I=0;I3;I+) for(int j=0;j3;j+) printf("%3d ",aIj);C)6 4 2 D)6 4 2 9 6 3 9 6 3printf("n"); A) 1 4 2 B) 1 4 2 1 1 4 1 1 1 3 2 1 3 2 11Every C program consists of at least how

73、many functions? A1 B2 C3 D42Which of the following words is reserved words (保留字) in C?Aabs Bchar Cstr Dsqrt4Which of the following identifiers is invalid?An BPAY_DAY C6Set Dnum56What is the value of the C expression 7 % 2 ?A1 B2 C2.5 D37Write a C expression for the following algebraic expression (3&

74、lt;y<9 ). Which of the following expression is valid? A3<y && y<9 B3<y | y<9 C3<y and y<9D3<y or y<99Which of the following Function declaration(函数声明)is valid?Aint f( a); Bvoid function(int a); Cint function A; Dvoid int(char a);10.What would the heading(函数首部) for

75、a value-returning function named Mul look like if it had two int parameters,num1 and num2, and returned 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 prog

76、rams and answer questions (5 marks for each item, total marks: 30) 1.1 The output of the following program is _.#include <stdio.h>     void main( )  

77、      int k, x, s, t;           x=3;s=0; t=x;         for(k=1; k<=3; k+)    t=t*10+x; s=s+t;  

78、60;  printf("%dn", s);          2.2 When input:  7 3 0 3 0 3  1 2 9 7 6 0<ENTER>, the output is _  #include <stdio.h

79、>     void main( )        int j, k, sub, x;int a5;               for(j=1; j<=2; j+)   for(k=0;

80、 k<5; k+)       scanf(“%d”, &ak);   scanf(“%d”, &x);   sub=-1;    for(k=0; k<5; k+)  ifAk=x)   sub=k;  printf("%dn", sub);

81、0; 3.3 The output of the following program is _  #include <stdio.h>     void main( )        long number, wt, x;       &

82、#160; x=number=10230;wt=1;         while(x!=0)   wt=wt*10;      x=x/10;      wt=wt/10;         while(number!=0) printf("

83、%dn", number/wt);   number=number%wt;   wt=wt/10;  4.4 When input:  3  9 8 6 5 3 7 1 2 4  2  1 2 3 4<ENTER>, the output is _

84、.#include "stdio.h" void main( )   int flag,i,j,k,col,n,ri,a66; for(ri=1; ri<=2; ri+)  scanf("%d",&n);  for(i=0; i<n; i+)      for(j=0; j<n; j

85、+)  scanf("%d",&aij);       flag=0;  for(i=0; i<n; i+)   col=0;       for(j=0; j<n; j+)       if Aicol<aij)  col=j;&#

86、160;     for (k=0; k<n; k+)       if Aicol<akcol)   break;   if(k>=n)  printf("a%d%d=%dn", i, col,aicol); flag=1;     if(!flag) 

87、60;printf("NOn");          5.5 When input:  how are you? <ENTER>, the output is _.#include <stdio.h> void main( )    int word; &

88、#160; char ch;     word=0;   while(ch=getchar()!='?') if (ch=' ') word=0;    else if(word=0)   word=1;     if(ch<='z'&&ch>='a')&#

89、160;     ch=ch-'a'+'A'        putchar(ch);     2When input: AabD <ENTER>, The output of the following program is _. #include

90、0;<stdio.h> void main() char s81; int i=0; gets(s); while (si!=0) if(si<=z&&si>=a) si=z+a-si; i+;  puts(s);  1. The following program will output _. #include "stdio.h"#define M 5int k = 2;int find_next(int start, int m );int main( ) int m = 1, 2, 3, 4, 0; int count, pre, start = 0; for( count = M; count>1; count- ) pre = find_next( start, m ); start = mpre; mpre = mstart; printf( "%dn",start ); printf("%dn",pre); return 0; int find_next( int s, int m )int i;fo

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论