浙江大学c程2002B试卷E.doc_第1页
浙江大学c程2002B试卷E.doc_第2页
浙江大学c程2002B试卷E.doc_第3页
浙江大学c程2002B试卷E.doc_第4页
浙江大学c程2002B试卷E.doc_第5页
已阅读5页,还剩4页未读 继续免费阅读

下载本文档

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

文档简介

C ProgrammingTEST PAPERTime: 8:30-10:30 am. June 20, 2003Important note: your answers must be written on the answer sheetSection 1: Single Choice(1 mark for each item, total 10 marks)1. The precedence of operator _ is the lowest one.A0|y0) is equivalent to _.A!(x0)&!(y0)B!x0&!y0C!x0|!y0D!(x0)|!(y0)4. The value of expression _ isnt 0。A1/2B!0C!EOFDNULL5. If x is a float variable, the value of expression (x=10/4) is _ 。A2.5B2.0C3D26. If variables are defined and assigned correctly, the expression _ is wrong.Aa&bBabC&xDa, b7. According to the declaration: int a10, *p=a; the expression _ is wrong.Aa9Bp5C*p+Da+8. _ is wrong.Achar str10; str=string;Bchar str =string;Cchar *p=string;Dchar *p; p=string;9. If all variables have been defined and declared in the following program, all the variables which can be used in function fun() are _. #include void fun(int x) static int y; return; int z; void main( ) int a,b; fun(a); Ax, yBx, y, zC a,b,y,zDa,b,x,y,z10. According to the declaration: int p5, *a5; the expression _ is correct.Ap=aBp0=a C*(a+1)=p Da0=2Section 2: Fill in the blanks(2 mark for each item, total 30 marks)1. According to the declaration: int a234,the number of elements of array a is _24_.2. Writing conditional expression_(x0)?1: (x=0)? 0:-1_ to calculate the value of y. 1 x0y= 0 x=0 -1 x03. The value of expression 1105 is _1_.4. The value of expression (101)&4 is_0_.5. The value of expression sizeof(“hello”) is_6_.6. The output of the following statements is _k=10,s=25_.int k, s;for(k=1, s=0; k10; k+)if (k%2=0) continue; s += k; printf(k=%d s=%d, k, s);7. The output of the following statements is _47_. #define MM(x,y) (x*y) printf(%d, MM(2+3,15);8. The output of the following statements is _k=1 s=30_.int k=1, s=0;switch (k) case 1: s+=10; case 2: s+=20; break; default: s+=3; printf(k=%d s=%d, k, s);9. The output of the following program is _1#2#3#_.# include int f( ) static int k; return +k;void main( ) int k; for(k=0;k3;k+) printf(%d#, f( );10. The output of the following program is _5_.f (int x) if(x=1) return 1;else return f(x-1)+f(x-2);void main( ) printf(%d, f(4);11. The output of the following statements is _2, 1_.int k=1, j=2, *p, *q, *t; p=&k; q=&j;t=p; p=q; q=t;printf(%d, %d,*p, k);12. The output of the following statements is _10#30#_.int c =10, 30, 5;int *pc;for(pc=c; pcc+2; pc+)printf(%d#, *pc);13. The output of the following statements is _FOUR, P_.char *st =ONE,TWO,FOUR,K;printf(%s, %cn, *(st+2), *st+1);14. The output of the following program is _0, 4_. #include void p(int *x,int y) + *x; y=y+2;void main() int x=0, y=3; p(&y, y); printf(%d, %d, x, y); 15. Writing the declaration _ with typedef, which makes CP a synonym for a character pointer array, 10 elements. typedef char *CP10;Section 3: Read each of the following programs and answer questions (5 marks for each item, total marks: 30)1. The output of the following program is _33#366#3699#_. #include void main( ) int k, x, s, t; x=3; s=0; t=x; for(k=1; k=3; k+) t=t*10+x;s=s+t; printf(%d#, s); 2. When input: 7 3 0 3 0 3 1 2 9 7 6 0, the output is _3#-1#_. #include void main( ) int j, k, sub, x; int a5; for(j=1; j=2; j+) for(k=0; k5; k+) scanf(“%d”, &ak); scanf(“%d”, &x); sub=-1; for(k=0; k5; k+) if(ak=x) sub=k; printf(%d#, sub); 3. The output of the following program is _1#0#2#3#_. #include void main( ) long number, wt, x; x=number=10230; wt=1; while(x!=0) wt=wt*10; x=x/10;wt=wt/10; while(number!=0) printf(%d#, number/wt); number=number%wt; wt=wt/10; 4. When input: 3 9 8 6 5 3 7 1 2 4 2 1 2 3 4, the output is _a00=9#a12=7#a11=4#_.#include stdio.hvoid main( ) int flag,i,j,k,col,n,ri,a66; for(ri=1; ri=2; ri+) scanf(%d,&n); for(i=0; in; i+) for(j=0; jn; j+) scanf(%d,&aij); flag=0; for(i=0; in; i+) col=0; for(j=0; jn; j+) if (aicolaij) col=j; for (k=0; kn; k+) if(aicol=n) printf(a%d%d=%d#, i, col,aicol); flag=1; if(!flag) printf(NO#); 5. When input: how are you? , the output is _How Are You?_.#include void main( ) int word;char ch; word=0;while(ch=getchar()!=?)if(ch= ) word=0;else if(word=0)word=1;if(ch=a)ch=ch-a+A;putchar(ch);6. If the following data are stored in text file a.txtone?two?1234?output?And the following data are stored in text file b.txtone?two?1204?input?The output of the following program is _3#0#2#_.# include # include void main() int count; char ch1,ch2; FILE *f1, *f2; if (f1 = fopen(a.txt,r) = NULL)printf(Cant open file : %sn, a.txt); exit(0);if (f2 = fopen(b.txt,r) = NULL)printf(Cant open file : %sn, b.txt); exit(0); count=0;while (!feof(f1)|!feof(f2) ch1=fgetc(f1); ch2=fgetc(f2); if(ch1!=ch2) printf(%c#%c#,ch1,ch2); printf(%d#, count); break; if(ch1=?) count+; fclose(f1); fclose(f2);Section 4: According to the specification, complete each program (2 mark for each blank, total: 30 marks)1If input is n(n0), calculate the value of s = 1/1! + 1/2! + 1/3! + + 1/n!.#include void main( ) int j, k, n; float f, s;scanf(%d, &n); (1) ; for (k=1 ; k=n; k+) (2) ; for(j=1; (3) ; j+) (4) ; s=s+1.0/f; printf(sum=%f, s);(1) s=0(2) f=1(3) j0), if its a prime number, print YES, otherwise print NO. (Prime numbers: an integral number not divisible without a remainder by any integral number other than itself and one. One isnt a prime number, but two is a prime number)。#include #include void main( ) int n; int prime(int m); scanf(%d, &n); if( (5) ) printf(YESn); elseprintf(NOn);int prime(int m) int i,n; if(m=1) return 0; n=sqrt(m); for(i=2; i=n; i+) if( (6) ) return (7) ; (8) ; (5) prime(n)(6) m%i=0(7) 0(8)return 13The definition of function f2 () is equivalent to the definition of function f1 ().int f1(char s ) int k=0; while(s

温馨提示

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

最新文档

评论

0/150

提交评论