资源预览内容
第1页 / 共6页
第2页 / 共6页
第3页 / 共6页
第4页 / 共6页
第5页 / 共6页
第6页 / 共6页
亲,该文档总共6页全部预览完了,如果喜欢就下载吧!
资源描述
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. 1. The precedence of operator _ is the lowest one.A0|y0) is equivalent to _.A!(x0)&!(y0) B!x0&!y0 C!x0|!y0 D!(x0)|!(y0)4. 4. The value of expression _ isnt 0。A1/2 B!0 C!EOF DNULL5. 5. If x is a float variable, the value of expression (x=10/4) is _ 。A2.5 B2.0 C3 D26. 6. If variables are defined and assigned correctly, the expression _ is wrong.Aa&b Bab C&x Da, b7. 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; 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 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, y Bx, y, z C a,b,y,z Da,b,x,y,z10. 10. According to the declaration: int p5, *a5; the expression _ is correct.Ap=a Bp0=a C*(a+1)=p Da0=2Section 2: Fill in the blanks( 2 mark for each item, total 30 marks)1. 1. According to the declaration: int a234,the number of elements of array a is _.2. 2. Writing conditional expression_ to calculate the value of y.1 x0y= 0 x=0-1 xint f( ) static int k; return +k;void main( ) int k;for(k=0;kvoid p(int *x,int y) + *x;y=y+2;void main() int x=0, y=3;p(printf(%d, %d, x, y);15. 15. Writing the declaration _ with typedef, which makes CP a synonym for a character pointer array, 10 elements.Section 3: Read each of the following programs and answer questions (5 marks for each item, total marks: 30)1. 1. The output of the following program is _.#include void main( ) int k, x, s, t;x=3;s=0; t=x;for(k=1; k, the output is _.#include void main( ) int j, k, sub, x;int a5; for(j=1; jvoid 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. 4. When input: 3 9 8 6 5 3 7 1 2 4 2 1 2 3 4, the output is _.#include stdio.hvoid main( ) int flag,i,j,k,col,n,ri,a66;for(ri=1; ri=n)printf(a%d%d=%d#, i, col,aicol);flag=1;if(!flag) printf(NO#);5. 5. When input: how are you? , the output is _.#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. 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 _.# 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, (1) ;for (k=1 ; k0), 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, if( (5) ) printf(YESn);elseprintf(NOn); int prime(int m) int i,n;if(m=1) return 0;n=sqrt(m);for(i=2; istruct studentchar name10; int score; ;void main( ) int k;struct student s30, *ptr;struct student *f(struct student *stud, int n);for(k=0; kname, ptr-score);struct student *f(struct student *stud, int n)struct student * pmax, *p;(13) ;for(p=stud; pscore pmax-score) (14) ;return (15) ;
网站客服QQ:2055934822
金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号