




已阅读5页,还剩3页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
提醒:考试失败你将仍有机会;警告:考试作弊你将失去学位。C ProgrammingTEST PAPERTime: 8:30-10:30 am. Jan 15, 2004Important note: your answers must be written on the answer sheetSection 1: Single Choice(2 mark for each item, total 20 marks)1. The declaration _ declares the variable which can hold the largest positive number.Aint a;Bchar b;Cfloat c;Ddouble d;2. The _ operator cannot be used as a unary-operator.A+B-C*D/3. _ is wrong if it is used as a character constant.A”1” B1 C1Dn4. If c is a character variable, its value is 1 or 0 after evaluating the expression _。Ac=getchar()!=EOFB(c=getchar()!=EOFCc = 0Dc = c c5. According to the declaration: int a10, *p=&a1; the last element of the array a is _.Aa10Bp8Cp9Dp106. The precedence of operator _ is the highest one.A+=B C? :D+7. The following code fragment prints out _.char s =student;printf(“%s%d”, s+3, sizeof(s); Astudent7Bdent7Cdent8Dstudent88. According to the following declaration, _ is valid.struct node char s10;int k; p5;Ap.k=2Bp0-k=2 C(p-s)0=aDp0.s=“a”9. According to the declaration: int (*p)10, p is a_.ApointerBarrayCfunctionDelement of a array10. Assume that the user of a program is asked to enter a day number (1-7) into an integer variable called day. In the following while loops, _ can be used to validate the day entered.A. while (day = 1 | day = 1 & day = 7) printf(ERROR 1 - 7 only, enter again: ); scanf(”%d”, &day); C. while (day 7) printf(ERROR 1 - 7 only, enter again: ); scanf(”%d”, &day); D. while (day = 7) printf(ERROR 1 - 7 only, enter again: ); scanf(”%d”, &day); Section 2: Fill in the blanks(2 mark for each item, total 30 marks)1. Write a conditional expression _ to calculate the maximum of x and y. 2. The value of expression 7 * 7 / 9 * 4 % 3 is _.3. The value of expression 10=10=10 is _.4. The value of expression 255 & 128 is_.5. The following code fragment prints out _.int a = 3, b;if ( a 5 ) b = 7;else if ( a 2 ) b = 6;else b = 5;printf(%d, b);6. The following code fragment prints out _.int a = 13;int b = 3;float x;x = a / b;printf (%.1f, x);7. The following code fragment prints out _.int j = 1, k = 2;printf (%d, %d#, j+, +k);printf (%d, %d, -j, k-);8. The following code fragment prints out _.int x, y;x = y = 3;switch (y) case 1: x = 0; break;case 2: x = 17; break;case 4: x = 9; break;printf (“%d”, x);9. The following code fragment prints out _.int array = 2, 8, 6, 11, 13, 2, 8, 2;int k; int total = 0;for ( k = 0; k 8; k+ ) if ( array k % 2) break;total += array k;printf ( “%d”, total );10. The output of the following statements is _. #define MM(x,y) (x)*(y)printf(%d, MM(4, 2+3)-8);11. The output of the program given below is _.#include int main (void)int k = 1; int a_function ( int j ); k = a_function ( k );printf ( %d , k );int a_function ( int j ) if ( j 3 ) j+;j = a_function ( j );printf ( %d# , j );return ( j );12. The following code fragment prints out _.int a = 1; int b = 2;int *x, *y;x = &a;y = &b;*x = *x + 1;x = y;*x = *x + 1;printf(%d, %d, a, b);13. To execute the command: prog at my home, the value of *(+argv)1 is_.14. The program given below prints out _.void melon (int g, int * h);int main (void) int a = 1, b = 2; melon ( a, &b ); printf ( a = %d, b = %d, a, b );void melon (int b, int * c) b+; *c = *c + b;15. Write a while loop that is equivalent to the for loop given below.for ( k = 0; k 10; k+ ) sum = sum + k;Section 3: Read each of the following programs and answer questions (6 marks for each item, total marks: 30)1. The output of the following program is _.#include stdio.hvoid main() int j, k; for (j=0; j3; j+) for (k=0; k3; k+) printf(%2d,(k+j+1)% 3 ? (k+j+1)%3 : 3 ); printf(#); 2. The output of the following program is _.#include void main() int i, k,m; int a8=60,75,63,92,87,64,79,21, s10; for(k=0; k10; k+) sk=0; for(i=0; i8; i+) k=ai/10; sk+; m=s0; k=1; while (km) m=sk; k+; printf(%d, m);3. The output of the following program is _.#include #includeint prime(int n) int i,m; if(n=1) return 0; m=sqrt(n); for(i=2;im;void main() int num,i; num=20; for(i=2;i=num;i+) while(prime(i)&(num%i=0) printf(%d ,i); num/=i; 4. The output of the following program is _.#include void main( ) int j, k; char c, s180=” a-b-e8-9”, s280; j=k=0;while(c=s1j+)!=0)if(s1j=-&s1j+1=c)j+;while(cs1j)s2k+=c+;elses2k+=c;s2k=0; printf(“%s”, s2);5. If the following data are stored in text file a.txtOne23Two45The output of the following program is _.# include # include void main() char ch; FILE *fp; if (fp = fopen(a.txt,r) = NULL)printf(Cant open file : %sn, a.txt); exit(0);while (!feof(fp) ch=fgetc(fp); if(ch=0 & ch=9) putchar(ch-0+A); fclose(fp);Section 4: According to the specification, complete each program (2 mark for each blank, total: 20 marks)1The program written below prints out the numbers between 1 and 1000, which equal the sum of the cubes of the digits. For example, one of the numbers printed out could be 153, because 153=1*1*1+5*5*5+3*3*3.#include void main( ) int digit, k, m, s;for (k=1; k=1000; k+) (1) ; m=k; while(m!=0) digit=m%10;s=s+digit*digit*digit; (2) ; if( (3) ) printf(%d , s); 2The function written below is a binary search one which decides if a particular value x occurs in the sorted array v. The elements of v are in increasing order. The function returns the position(a number between 0 and n-1) if x occurs in v, and 1 if not. int binasearch(int x, int v, int n) int low, high, mid; low=0;high=n-1;while( (4) ) mid=(low+high)/2; if( (5) ) high=mid-1; else if( (6) ) low=mid+1; else return mid; (7) ;3The de
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 热点练05 课外文言文(道理启示类寓言)-2024年中考语文专练
- 酸与碱的中和反应课件
- CN120202875A 一种金耳液体菌种自动接种装置及其接种方法
- CN120198169A 一种充电场站占位管理方法、装置、电子终端及存储介质
- 老师安全培训知识点课件
- 老师不会使用课件的原因
- 老人护理知识培训内容
- 老人安全与防护知识培训课件
- 建筑施工高处坠落防治技术
- 2025版碳晶片工程招投标代理合同
- 道路运输安全员考试题库及答案
- 2025重庆某国有企业招聘新媒体运营(偏拍摄剪辑)参考题库含答案
- 2025年秋期新教材部编人教版一年级上册道德与法治教学计划+进度表
- 医院绩效考核指标体系设计与实施
- 2025年农业农村局公务员招聘面试指南与模拟题解析
- 2025年北师大版新教材数学三年级上册教学计划(含进度表)
- 港珠澳大桥总体设计及关键技术-课件
- 舌尖上的历史与文化智慧树知到期末考试答案2024年
- 静脉血栓栓塞症抗凝治疗微循环血栓防治专家共识
- 常规保养双人作业流程新模板汇总
- 数字化管道综述
评论
0/150
提交评论