版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、浙江大学“程序设计基础-C”试题卷2001-2002学年春季学期考试时间:2002年6月30日下午2:00-4:00注意:答题内容必须写在答题卷上,写在本试题卷上无效一单项选择题(每题2分,共20分)1.C语言程序的三种基本结构是顺序结构、选择结构和结构。2.A.递归B.转移下列运算符中,优先级最高的是。C.循环D.嵌套3.A.-B.+表达式!(x0&y0)等价于。C.&D.=A.!(x0)|!(y0)B.!x0|!y0C.!x0&!y0D.!(x0)&!(y0)4.表达式sizeof(nsum=%dn)的值是_。5.A.8B.9以下选项中不正确的实型常量是。C.10D.116.A.0.23E
2、B.2.3e-1表达式的值不是1。C.1E3.2D.2.3e0A.0?0:1B.5%4C.!EOFD.!NULL7.数组定义为inta1111,则数组a有_个数组元素。A.12B.144C.100D.1218.对于以下的变量定义,表达式是不正确的。structnodeintj,k;x,*p=&x;9.A.p-k=2B.(*p).k=2不正确的赋值或赋初值的方式是。C.x.k=2D.x-k=2A.charstr=string;B.charstr10;str=string;C.char*p=string;D.char*p;p=string;10.设程序中不再定义新的变量,写出在函数main中可以使
3、用的所有变量#includeintz;intp(intx)staticinty;return(x+y);voidmain()inta,b;printf(%dn,p(a);Aa,bBa,b,zCa,b,y,zDa,b,x,y,z二、填空题(每题2分,共30分)设字符型变量ch的值是小写英文字母,将它转换为相应大写字母的表达式是TOC o 1-5 h z2.表达式101人5)的值是。下列程序段的输出结果是。inta=1;longb=a*0 x12345678;printf(%xn,b);设变量已正确定义,在程序段B中填入正确的内容,使程序段A和程序段B等价。程序段Afor(k=s=0;k=10;s
4、+=ak+)if(ak0)break;程序段Bfor(k=0,s=0;s+=ak+)if()break;下列程序段的输出结果是。#defineT10#defineMD3*Tprintf(%d,30/MD);下列程序段的输出结果是。intk,s;for(k=s=0;k10&s=10;s+=k)k+;printf(k=%d,s=%d,k,s);下列程序的输出结果是。#includeintf(intm)staticintk=2;k+;returnk+m;voidmain()ints;s=f(2);printf(%d,%dn,s,f(s);TOC o 1-5 h z对于以下递归函数f,调用f的返回值是
5、。f(intn)return(n=0)?n:f(n-1)+f(n-2);下列程序段的输出结果是。intc=10,0,-10;int*k=c+2;printf(%d,*k-);下列程序段的输出结果是。intk=1,j=2,*p=&k,*q=p;p=&j;printf(%d,%d,*p,*q);下列程序的输出结果是。#includechar*f(char*str)returnstr=fun;voidmain()char*str=one;printf(%s,%cn,f(str)+1,*f(str)+1);下列程序的输出结果是。#includevoidp(int*x,inty)+*x;y-;voidm
6、ain()intx=0,y=3;p(&x,y);printf(%d,%d,x,y);下列程序的输出结果是。#includestdio.hvoidmain()intj,k,a22;for(k=1;k3;k+)for(j=1;j3;j+)ak-1j-1=(k/j)*(j/k);for(k=0;k2;k+)for(j=0;j2;j+)printf(%d,akj);用typedef定义一个指向函数的指针类型FP,该函数的返回值为整型。三、程序阅读题(每题5分,共15分)1.输入c2470f?后,下列程序的输出结果是,该程序的主要功能是#includestdio.hintmain()charch;lon
7、gnumber=0;while(ch=getchar()6)while(ch!=?&ch=0&ch=6)number=number*7+ch-0;printf(%ld#,number);ch=getchar();2输入4后,下列程序的输出结果是。#includestdio.hintmain()intj,k,n;floatf,s;scanf(%d,&n);s=0;f=1;for(k=1;k=n;k+)for(j=1;jk;j+)f=f*k;s=s+f;printf(%.0f#,s);3输入55926369-1后,下列程序的输出结果是#include#includestructlinkintmar
8、k;structlink*next;voidf(structlink*);main()structlink*head,*p;head=(structlink*)malloc(sizeof(structlink);head-mark=0;head-next=NULL;f(&head);for(p=head;p!=NULL;p=p-next)printf(%d#,p-mark);voidf(structlink*head)intmark;structlink*p;scanf(%d,&mark);if(markmark+;return;elsep=(structlink*)malloc(sizeof
9、(structlink);p-mark=mark;p-next=*head;*head=p;f(head);四、程序填空题(每空2分,共20分)输入10个浮点数,调用函数f(x)计算并输出相应的函数值。f(x)的功能是计算分段函数:TOC o 1-5 h zx2+2x+1x0#includeif(xvO)(2);else;elsereturn3;voidmain()intk;floatx;for(k=1;k=10;k+)scanf(%f,&x);printf(y=%fn,f(x);函数sort使用冒泡法将一维整型数组中各元素按值从大到小排序。voidsort(inta,intn)intk,j,
10、t;for(k=1;kn;k+)for(;jn-k;j+)if()输入1个长整数,求各位数字的平方和。例如:输入-123,输出14。#includevoidmain()intdigit;longin,s;scanf(%ld,&in);TOC o 1-5 h z;;while(in0);s=s+digit*digit;printf(sum=%ldn,s);五、编程题(共15分)1函数ff(str,ch)的功能是统计并返回字符ch在字符串str中出现的次数。例如:调用ff(every,e)后返回2,因为在字符串every中字符e出现了2次。2.从键盘输入一个字符ch,输出该字符在文本文件input
11、.txt的每一行中出现的次数。(必须调用第1题定义的函数ff统计ch的出现次数)。例如:如果文件input.txt中存放了下列数据:every121amastudent.运行程序,并输入e后,输出201浙江大学“程序设计基础-C”参考答案2001-2002学年春季学期(2002年6月30日)一、单项选择题(每题2分,共20分)4B9B5AC10B1C2A6C7D3A8D二、填空题(每题2分,共30分)1ch-a+A或toupper(ch)213045678或123456785ak10(错1项扣1分)61007k=5,s=15(错1项扣1分)85,9错1个数字扣1分)9-210-10112,1(
12、错1个数字扣1分)12un,g(un1分,g1分)131,3(错1个数字扣1分)141,0,0,1分)(错1个数字扣115typedefint(*FP)();(扣1分)(错1项三、程序阅读题(每题5分,共15分)12#18#七进制转换十进制错1项扣2分31#3#21#1173#错1项扣2分370#63#92#55#0#错1项扣1分四、程序填空题(每空2分,共20分)(1)floatf(floatx)(2)returnx*x+2*x+1(3)if(x=0)return0(4)j=0(5)ajaj+1(6)t=aj+1;aj+1=aj;aj=t;(7)if(in0)in=-in(8)s=0(7)、
13、(8)可以互换(9)digit=in%10(10)in=in/10五、编程题(共15分)1、intff(char*str,charch)/*说明1分*/intcount=0;while(*str)/*循环3分条件、查找、str递增各1分*/if(*str=ch)count+;str+;returncount;/*返回1分*/2、#inelude/*头文件、变量说明、打开关闭文件、输入ch共2分*/#includevoidmain()charch,c,s80;intk;FILE*fp;if(fp=fopen(input.txt,r)=NULL)printf(errorn);exit(0);ch=
14、getchar();k=0;while(1)/*循环+beaak1分*/c=fgetc(fp);/*读入1分*/if(c=n|c=EOF)/*共6分*/sk=0;k=0;printf(%dn,ff(s,ch);if(c=EOF)break;elsesk+=c;fclose(fp);k=0;/*循环判断1分*/*读入1分*/*共5分*/while(!feof(fp)c=fgetc(fp);if(c!=n)sk+=c;elsesk=0;k=0;printf(%dn,f(s,ch);if(c!=n)/*处理最后1行1分*/sk=0;printf(%dn,ff(s,ch);CProgrammingTE
15、STPAPERTime:8:30-10:30am.June20,2003Importantnote:youranswersmustbewrittenontheanswersheetSection1:SingleChoice(1markforeachitem,total10marks)D=D1.0D!(x0)|!(y0)DNULLTheprecedenceofoperatoristhelowestone.TOC o 1-5 h zA0|y0)isequivalentto.A!(x0)&!(y0)B!x0&!y0C!x0|!y0Thevalueofexpressionisnt0。A1/2B!0C!
16、EOFIfxisafloatvariable,thevalueofexpression(x=10/4)is。A2.5B2.0C3D2Ifvariablesaredefinedandassignedcorrectly,theexpressioniswrong.A.a&bB.aAbC.&xD.a,bAccordingtothedeclaration:inta10,*p=a;theexpressioniswrong.A.a9B.p5C.*p+D.a+iswrong.A.charstr10;str=string;B.charstr=string;C.char*p=string;D.char*p;p=s
17、tring;Ifallvariableshavebeendefinedanddeclaredinthefollowingprogram,allthevariableswhichcanbeusedinfunctionfun()are.#includevoidfun(intx)staticinty;return;intz;voidmain()inta,b;fun(a);A.x,yB.x,y,zC.a,b,y,zD.a,b,x,y,zAccordingtothedeclaration:intp5,*a5;theexpressioniscorrect.A.p=aB.p0=aC.*(a+1)=pD.a0
18、=2Section2:Fillintheblanks(2markforeachitem,total30marks)Accordingtothedeclaration:inta234,thenumberofelementsofarrayaisWritingconditionalexpressiontocalculatethevalueofy.TOC o 1-5 h z1x0y=0 x=01-1x0Thevalueofexpression1105is.Thevalueofexpression(101)&4is.Thevalueofexpressionsizeof(“hello”)isTheoutp
19、k,s;for(k=1,s=0;k10;k+)if(k%2=0)continue;s+=k;printf(k=%ds=%d,k,s);Theoutputofthefollowingstatementsis.#defineMM(x,y)(x*y)printf(%d,MM(2+3,15);Tk=1,s=0;switch(k)case1:s+=10;case2:s+=20;break;default:s+=3;printf(k=%ds=%d,k,s);Theou
20、tputofthefollowingprogramis.#includeintf()staticintk;return+k;voidmain()intk;for(k=0;k3;k+)printf(%d#,f();Theoutputofthefollowingprogramis.f(intx)if(x=1)return1;elsereturnf(x-1)+f(x-2);voidmain()printf(%d,f(4);Tk=1,j=2,*p,*q,*t;p=&k;q=&j;t=p;p=q;q=t;printf(%d,%d
21、,*p,k);Tc=10,30,5;int*pc;for(pc=c;pcc+2;pc+)printf(%d#,*pc);Theoutputofthefollowingstatementsis.char*st=ONE,TWO,FOUR,K;printf(%s,%cn,*(st+2),*st+1);Theoutputofthefollowingprogramis.#includevoidp(int*x,inty)+*x;y=y+2;voidmain()intx=0,y=3;p(&y,y);printf(%d,%d,x,y)
22、;Writingthedeclarationwithtypedef,whichmakesCPasynonymforacharacterpointerarray,10elements.Section3:Readeachofthefollowingprogramsandanswerquestions(5marksforeachitem,totalmarks:30)Theoutputofthefollowingprogramis.#includevoidmain()intk,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);W
23、heninput:730303129760,theoutputis.#includevoidmain()intj,k,sub,x;inta5;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);Theoutputofthefollowingprogramis.#includevoidmain()longnumber,wt,x;x=number=10230;wt=1;while(x!=0)wt=wt*10;x=x/10;wt=w
24、t/10;while(number!=0)printf(%d#,number/wt);number=number%wt;wt=wt/10;Wheninput:398653712421234,theoutputis#includestdio.hvoidmain()intflag,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;k
25、n;k+)if(aicol=n)printf(a%d%d=%d#,i,col,aicol);flag=1;if(!flag)printf(NO#);Wheninput:howareyou?,theoutputis#includevoidmain()intword;charch;word=0;while(ch=getchar()!=?)if(ch=)word=0;elseif(word=0)word=1;if(ch=a)ch=ch-a+A;putchar(ch);Ifthefollowingdataarestoredintextfilea.txtone?two?1234?output?Andth
26、efollowingdataarestoredintextfileb.txtone?two?1204?input?Theoutputofthefollowingprogramis.#include#includevoidmain()intcount;charch1,ch2;FILE*f1,*f2;if(f1=fopen(a.txt,r)=NULL)printf(Cantopenfile:%sn,a.txt);exit(0);if(f2=fopen(b.txt,r)=NULL)printf(Cantopenfile:%sn,b.txt);exit(0);count=0;while(!feof(f
27、1)|!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);Section4:Accordingtothespecification,completeeachprogram(2markforeachblank,total:30marks)1Ifinputisn(n0),calculatethevalueofs=1/1!+1/2!+1/3!+1/n!.#includevoidmain(
28、)intj,k,n;floatf,s;scanf(%d,&n);(1);for(k=1;k0),ifitsaprimenumber,printYES,otherwiseprintNO.(Primenumbers:anintegralnumbernotdivisiblewithoutaremainderbyanyintegralnumberotherthanitselfandone.Oneisntaprimenumber,buttwoisaprimenumber)。#include#includevoidmain()intn;intprime(intm);scanf(%d,&n);if(5)pr
29、intf(YESn);elseprintf(NOn);intprime(intm)inti,n;if(m=1)return0;n=sqrt(m);for(i=2;i=n;i+)if(6)return(7)(8);3Thedefinitionoffunctionf2()isequivalenttothedefinitionoffunctionf1().intf1(chars)intk=0;while(sk!=0)k+;returnk;intf2(char*s)char*ss;;while(*s+!=(10);return(11);4Wheninputisthenamesandscoresof30
30、students,printthenameandscoreofthestudentwhohavethehighestscore.#includestructstudentcharname10;intscore;voidmain()intk;structstudents30,*ptr;structstudent*f(structstudent*stud,intn);for(k=0;kname,ptr-score);structstudent*f(structstudent*stud,intn)structstudent*pmax,*p;(13);for(p=stud;pscorepmax-sco
31、re)(14)return(15):浙江大学“c程序设计及实验”参考答案2002-2003学年春季学期(2003年6月20日)一、单项选择题(每题1分,共10分)1D2D3A4B5B6C7D8A9A10C二、填空题(每题2分,共30分)1242x0?1:(x=0)?0:-13140566k=10s=25(错1项扣1分)7478k=1s=30(错1项扣1分1#2#3#(错1个数字扣159分)10112,1(错1个数字扣1分)1210#30#1分)(错1个数字扣FOUR,P(错1个项扣10,4(错1个数字扣13分)141分)typedefchar*CP10:错1项15扣1分)三、程序阅读题(每题5
32、分,共30分)133#366#3699#错1项扣2分33#-1#错1项扣2分31#0#2#3#错1项扣2分4a00=9#a12=7#a11=4错1项扣2分5HowAreYou错1项扣2分63#0#2#错1项扣2分四、程序填空题(每空2分,共30分)_s=0(2)_f=1(3)jv=k(4)_f=f*j(5)prime(n)(6)m%i=O(7)_0(8)return1(9)ss=s(10)卫s-ss-1(12)ptr=f(s,30)(13)pmax=stud(14)pmax=p(15)pmax提醒:考试失败你将仍有机会;警告:考试作弊你将失去学位。CProgrammingTESTPAPERTi
33、me:8:30-10:30am.Jan15,2004Importantnote:youranswersmustbewrittenontheanswersheetdeclaresthevariablewhichcanholdthelargestpositiveSection1:SingleChoice(2markforeachitem,total20marks)Thedeclarationnumber.Ddoubled;D/DnAinta;Bcharb;Cfloatc;Theoperatorcannotbeusedasaunary-operator.TOC o 1-5 h zA+B-C*iswr
34、ongifitisusedasacharacterconstant.A”1”B1C1Ifcisacharactervariable,itsvalueis1or0afterevaluatingtheexpression。c=getchar()!=EOFB.(c=getchar()!=EOFC.c=OD.c=cAcAccordingtothedeclaration:inta10,*p=&a1;thelastelementofthearrayaisA.a1OB.p8C.p9D.p1OTheprecedenceofoperatoristhehighestone.A.+=B.C.?:D.+Thefoll
35、owingcodefragmentprintsout.chars=student;printf(“%s%d”,s+3,sizeof(s);A.student7B.dent7C.dent8D.student8Accordingtothefollowingdeclaration,isvalid.structnodechars1O;intk;p5;A.p.k=2B.pO-k=2C.(p-s)O=aD.pO.s=“a”Accordingtothedeclaration:int(*p)1O,pisa.A.pointerB.arrayC.functionD.elementofaarrayAssumetha
36、ttheuserofaprogramisaskedtoenteradaynumber(1-7)intoanintegervariablecalledday.Inthefollowingwhileloops,canbeusedtovalidatethedayentered.while(day=1|day=1&day=7)printf(ERROR1-7only,enteragain:);scanf(”%d”,&day);while(day7)printf(ERROR1-7only,enteragain:);scanf(”%d”,&day);while(day=7)printf(ERROR1-7on
37、ly,enteragain:);scanf(”%d”,&day);Section2:Fillintheblanks(2markforeachitem,total30marks)Writeaconditionalexpressiontocalculatethemaximumofxandy.TOC o 1-5 h zThevalueofexpression7*7/9*4%3is.Thevalueofexpression10=10=10is.Thevalueofexpression255&128is.Ta=3,b;if(a5)b
38、=7;elseif(a2)b=6;elseb=5;printf(%d,b);Ta=13;intb=3;floatx;x=a/b;printf(%.1f,x);Tj=1,k=2;printf(%d,%d#,j+,+k);printf(%d,%d,-j,k-);Tx,y;x=y=3;switch(y)case1:x=0;break;case2:x=17;break;case4:x=9;
39、break;printf(“%d”,x);Tarray=2,8,6,11,13,2,8,2;intk;inttotal=0;for(k=0;k8;k+)if(arrayk%2)break;total+=arrayk;printf(“%d”,total);Theoutputofthefollowingstatementsis.#defineMM(x,y)(x)*(y)printf(%d,MM(4,2+3)-8);Theoutputoftheprogramgivenbelowis.#includeintmain(void)in
40、tk=1;inta_function(intj);k=a_function(k);printf(%d,k);inta_function(intj)if(j3)j+;j=a_function(j);printf(%d#,j);return(j);Ta=1;intb=2;int*x,*y;x=&a;y=&b;*x=*x+1;x=y;*x=*x+1;printf(%d,%d,a,b);Toexecutethecommand:progatmyhome,thevalueof*(+argv)1isTheprogramgivenbelo
41、wprintsout.voidmelon(intg,int*h);intmain(void)inta=1,b=2;melon(a,&b);printf(a=%d,b=%d,a,b);voidmelon(intb,int*c)b+;*c=*c+b;Writeawhileloopthatisequivalenttotheforloopgivenbelow.for(k=0;k10;k+)sum=sum+k;Section3:Readeachofthefollowingprogramsandanswerquestions(6marksforeachitem,totalmarks:30)Theoutpu
42、tofthefollowingprogramis.#includestdio.hvoidmain()intj,k;for(j=0;j3;j+)for(k=0;k3;k+)printf(%2d,(k+j+1)%3?(k+j+1)%3:3);printf(#);Theoutputofthefollowingprogramis.#includevoidmain()inti,k,m;inta8=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+;print
43、f(%d,m);Theoutputofthefollowingprogramis.#include#includeintprime(intn)inti,m;if(n=1)return0;m=sqrt(n);for(i=2;im;voidmain()intnum,i;num=20;for(i=2;i=num;i+)while(prime(i)&(num%i=0)printf(%d,i);num/=i;Theoutputofthefollowingprogramis.#includevoidmain()intj,k;charc,s180=”a-b-e8-9”,s280;j=k=0;while(c=
44、s1j+)!=0)if(s1j=-&s1j+1=c)j+;while(cs1j)s2k+=c+;elses2k+=c;s2k=0;printf(“%s”,s2);Ifthefollowingdataarestoredintextfilea.txtOne23Two45Theoutputofthefollowingprogramis.#include#includevoidmain()charch;FILE*fp;if(fp=fopen(a.txt,r)=NULL)printf(Cantopenfile:%sn,a.txt);exit(0);while(!feof(fp)ch=fgetc(fp);
45、if(ch=0&ch=9)putchar(ch-0+A);fclose(fp);Section4:Accordingtothespecification,completeeachprogram(2markforeachblank,total:20marks)1Theprogramwrittenbelowprintsoutthenumbersbetween1and1000,whichequalthesumofthecubesofthedigits.Forexample,oneofthenumbersprintedoutcouldbe153,because153=1*1*1+5*5*5+3*3*3.#includevoidmain()intdigit,k,m,s;for(k=1;k=1000;k+)(1);m=k;while(m!=0)digit=m%10
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2026中国科学院化学研究所博士后招聘备考题库及一套答案详解
- 企业人力资源管理制度规范
- 2026中国科学院高能物理研究所科研计划处副处长岗位招聘1人备考题库及答案详解1套
- 2026年反电信诈骗知识竞赛试题及答案(共三套)
- 2026年生态修复与价值重塑项目商业计划书
- 2026年知识产权质押融资体系项目公司成立分析报告
- 2026年智能制造标准体系项目公司成立分析报告
- 2026年跨境智慧农业平台项目营销方案
- 社区安全管理培训课件
- 2026年睡眠追踪器项目营销方案
- 中小企业专利质量控制指引编制说明
- 旅游行业安全风险管控与隐患排查方案
- 专题15 物质的鉴别、分离、除杂、提纯与共存问题 2024年中考化学真题分类汇编
- DL-T5418-2009火电厂烟气脱硫吸收塔施工及验收规程
- 复方蒲公英注射液在痤疮中的应用研究
- 高考数学专题:导数大题专练(含答案)
- 腘窝囊肿的关节镜治疗培训课件
- 淮安市2023-2024学年七年级上学期期末历史试卷(含答案解析)
- 课件:曝光三要素
- 2023-2024学年山东省淄博市临淄区八年级(上)期末数学试卷(五四学制)(含解析)
- GB/T 10802-2023通用软质聚氨酯泡沫塑料
评论
0/150
提交评论