浙江大學c程2023B試卷E_第1頁
浙江大學c程2023B試卷E_第2頁
浙江大學c程2023B試卷E_第3頁
浙江大學c程2023B試卷E_第4頁
浙江大學c程2023B試卷E_第5頁
已閱讀5頁,還剩14頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領

文檔簡介

本文格式為Word版,下載可任意編輯——浙江大學c程2023B試卷E

浙江大學c程2023B試卷E

《CProgramming》TESTPAPER

Time:8:30-10:30am.June20,2023

Importantnote:youranswersmustbewrittenontheanswersheet

Section1:SingleChoice(1markforeachitem,total10marks)

1.Theprecedenceofoperator_____isthelowestone.

A.B.!=C.D.=

2._____iswrongifitisusedasanintegerconstant.

A.0xaB.010LC.10D.1.0

3.Theexpression!(x0||y0)isequivalentto_____.

A.!(x0)!(yB.!x0!y0C.!x0||!y0D.!(x0)||!(y0)

0)

4.Thevalueofexpression______isn’t0。

A.1/2B.!’\0’C.!EOFD.NULL

5.Ifxisafloatvariable,thevalueofexpression(x=10/4)is_____。

A.2.5B.2.0C.3D.2

6.Ifvariablesaredefinedandassignedcorrectly,theexpression______iswrong.

A.abB.a^bC.xD.a,b

7.Accordingtothedeclaration:inta[10],*p=a;theexpression______iswrong.

A.a[9]B.p[5]C.*p++D.a++

8.______iswrong.

A.charstr[10];str=string;B.charstr[]=string;

C.char*p=string;D.char*p;p=string;

9.Ifallvariableshavebeendefinedanddeclaredinthefollowingprogram,allthevariables

whichcanbeusedinfunctionfun()are______.

#includestdio.h

voidfun(intx)

{staticinty;

……

return;

}

intz;

voidmain()

{inta,b;

fun(a);

……

}

A.x,yB.x,y,zC.a,b,y,zD.a,b,x,y,z

10.Accordingtothedeclaration:intp[5],*a[5];theexpression______iscorrect.

A.p=aB.p[0]=aC.*(a+1)=pD.a[0]=2

《CProgramming》TESTPAPER,June20,20231/8

浙江大學c程2023B試卷E

Section2:Fillintheblanks(2markforeachitem,total30marks)

1.Accordingtothedeclaration:inta[2][3][4],thenumberofelementsofarrayais___24__.

2.Writingconditionalexpression___(x0)?1:(x==0)?0:-1___tocalculatethevalueofy.1x0

y=0x=0

-1x0

3.Thevalueofexpression1105is__1___.

4.Thevalueofexpression~(101)4is___0___.

5.Thevalueofexpressionsizeof(“hello〞)is___6___.

6.Theoutputofthefollowingstatementsis__k=10,s=25___.

intk,s;

for(k=1,s=0;k10;k++){

if(k%2==0)continue;

s+=k;

}

printf(k=%ds=%d,k,s);

7.Theoutputofthefollowingstatementsis__47___.

#defineMM(x,y)(x*y)

printf(%d,MM(2+3,15));

8.Theoutputofthefollowingstatementsis__k=1s=30___.

intk=1,s=0;

switch(k){

case1:s+=10;

case2:s+=20;break;

default:s+=3;

}

printf(k=%ds=%d,k,s);

9.Theoutputofthefollowingprogramis__1#2#3#___.

#includestdio.h

intf()

{staticintk;

return++k;

}

voidmain()

{intk;

for(k=0;k3;k++)

printf(%d#,f());

}

10.Theoutputofthefollowingprogramis__5___.

《CProgramming》TESTPAPER,June20,20232/8

浙江大學c程2023B試卷E

f(intx)

{

if(x=1)return1;

elsereturnf(x-1)+f(x-2);

}

voidmain()

{printf(%d,f(4));

}

11.Theoutputofthefollowingstatementsis__2,1___.

intk=1,j=2,*p,*q,*t;

p=k;q=j;

t=p;p=q;q=t;

printf(%d,%d,*p,k);

12.Theoutputofthefollowingstatementsis__10#30#___.

intc[]={10,30,5};

int*pc;

for(pc=c;pcc+2;pc++)

printf(%d#,*pc);

13.Theoutputofthefollowingstatementsis___FOUR,P__.

char*st[]={ONE,TWO,FOUR,K};

printf(%s,%c\n,*(st+2),**st+1);

14.Theoutputofthefollowingprogramis__0,4___.

#includestdio.h

voidp(int*x,inty)

{++*x;

y=y+2;

}

voidmain()

{intx=0,y=3;

p(y,y);

printf(%d,%d,x,y);

}

15.Writingthedeclaration_____withtypedef,whichmakesCPasynonymforacharacter

pointerarray,10elements.typedefchar*CP[10];

Section3:Readeachofthefollowingprogramsandanswerquestions(5marksforeachitem,totalmarks:30)

1.Theoutputofthefollowingprogramis__33#366#3699#___.

#includestdio.h

voidmain()

{intk,x,s,t;

《CProgramming》TESTPAPER,June20,20233/8

浙江大學c程2023B試卷E

x=3;

s=0;t=x;

for(k=1;k=3;k++){

t=t*10+x;

s=s+t;

printf(%d#,s);

}

}

2.Wheninput:730303129760ENTER,theoutputis____3#-1#___.

#includestdio.h

voidmain()

{intj,k,sub,x;

inta[5];

for(j=1;j=2;j++){

for(k=0;k5;k++)

scanf(“%d〞,a[k]);

scanf(“%d〞,x);

sub=-1;

for(k=0;k5;k++)

if(a[k]==x)sub=k;

printf(%d#,sub);

}

}

3.Theoutputofthefollowingprogramis__1#0#2#3#___.

#includestdio.h

voidmain()

{longnumber,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;

《CProgramming》TESTPAPER,June20,20234/8

浙江大學c程2023B試卷E

wt=wt/10;

}

}

4.Wheninput:398653712421234ENTER,theoutputis

____a[0][0]=9#a[1][2]=7#a[1][1]=4#___.

#includestdio.h

voidmain()

{intflag,i,j,k,col,n,ri,a[6][6];

for(ri=1;ri=2;ri++){

scanf(%d,n);

for(i=0;in;i++)

for(j=0;jn;j++)

scanf(%d,a[i][j]);

flag=0;

for(i=0;in;i++){

col=0;

for(j=0;jn;j++)

if(a[i][col]a[i][j])col=j;

for(k=0;kn;k++)

if(a[i][col]a[k][col])break;

if(k=n){

printf(a[%d][%d]=%d#,i,col,a[i][col]);

flag=1;

}

}

if(!flag)printf(NO#);

}

}

5.Wheninput:howareyou?ENTER,theoutputis___HowAreYou?____.

#includestdio.h

voidmain()

{intword;

charch;

word=0;

while((ch=getchar())!='?'){

if(ch=='')word=0;

elseif(word==0){

word=1;

《CProgramming》TESTPAPER,June20,20235/8

浙江大學c程2023B試卷E

if(ch='z'ch='a')

ch=ch-'a'+'A';

}

putchar(ch);

}

}

6.Ifthefollowingdataarestoredintextfilea.txt

one?two?1234?output?

Andthefollowingdataarestoredintextfileb.txt

one?two?1204?input?

Theoutputofthefollowingprogramis__3#0#2#___.

#includestdio.h

#includestdlib.h

voidmain()

{intcount;

charch1,ch2;

FILE*f1,*f2;

if((f1=fopen(a.txt,r))==NULL){

printf(Can'topenfile:%s\n,a.txt);

exit(0);

}

if((f2=fopen(b.txt,r))==NULL){

printf(Can'topenfile:%s\n,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);

}

《CProgramming》TESTPAPER,June20,20236/8

浙江大學c程2023B試卷E

Section4:Accordingtothespecification,completeeachprogram(2markforeachblank,total:30marks)

1.Ifinputisn(n0),calculatethevalueofs=1/1!+1/2!+1/3!+……+1/n!.

#includestdio.h

voidmain()

{intj,k,n;

floatf,s;

scanf(%d,n);

;

for(k=1;k=n;k++){

;

;j++)

;

s=s+1.0/f;

}

printf(sum=%f\,s);

}

(1)s=0

(2)f=1

(3)j=k

(4)f=f*j

2.Wheninputisn(n0),ifit’saprimenumber,printYES,otherwiseprintNO.(Primenumbers:anintegralnumbernotdivisiblewithoutaremainderbyanyintegralnumberotherthanitselfandone.Oneisn’taprimenumber,buttwoisaprimenumber)。

#includestdio.h

#includemath.h

voidmain()

{

intn;

intprime(intm);

scanf(%d,n);

)

printf(YES\n);

else

printf(NO\n);

}

《CProgramming》TESTPAPER,June20,20237/8

浙江大學c程2023B試卷E

intprime(intm)

{inti,n;

if(m==1)return0;

n=sqrt(m);

for(i=2;i=n;i++)

;

;

}

(5)prime(n)

(6)m%i==0

(7)0

(8)return1

3.Thedefinitionoffunctionf2()isequivalenttothedefinitionoffunctionf1().

intf1(chars[])intf2(char*s)

{intk=0;{char*ss;

while(s[k]!='\0');

k+

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經權益所有人同意不得將文件中的內容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
  • 6. 下載文件中如有侵權或不適當內容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論