试题3(每小题3分,共12分)
阅读下列程序说明和程序,在每小题提供的若干可选答案中,挑选一个正确答案。
【程序说明】
输入一个字符串和一个正整数m,将该字符串中的前m个字符复制到另一个字符串中,再输出后一个字符串。
运行示例1:
Enterastring:
103+895=?
Enteraninteger:
6
Thenewstringis103+89
运行示例2:
Enterastring:
103+895=?
Enteraninteger:
60
Thenewstringis103+895=?
运行示例3:
Enterastring:
103+895=?
Enteraninteger:
0
Thenewstringis
【程序】
#include
#include<(9)>
voidmain()
{chars[80],t[80],i,m;
printf("Enterastring:
");
gets(s);
printf("Enteraninteger:
");
scanf("%d",&m);
for(i=0;(10);i++)
(11);
(12)
printf("Thenewstringis");
puts(t);
}
【供选择的答案】
(9) A、ctype.h B、math.h
C、stdio.h D、string.h
(10)A、i='\0'
C、s[i]!
='\0'&&i='\0'||i(11)A、*s++=*t++ B、t[i]=s[i]
C、*t++=*s++ D、s[i]=t[i]
(12) A、t[i]='\0'; B、;
C、*++s='\0'; D、*++t='\0';
试题4(每小题3分,共12分)
阅读下列程序并回答问题,在每小题提供的若干可选答案中,挑选一个正确答案。
【程序】
#include
voidmain()
{ints,x1,y1,z1,x2,y2,z2;
printf("Enter6integers:
");
scanf("%d%d%d%d%d%d",&x1,&y1,&z1,&x2,&y2,&z2);
s=f(x2,y2,z2)-f(x1,y1,z1);
printf("%d\n",s);
}
f(intx,inty,intz)
{intk,n;
inttab[2][13]={
{0,31,28,31,30,31,30,31,31,30,31,30,31},
{0,31,29,31,30,31,30,31,31,30,31,30,31}
};
n=(x%4==0&&x%100!
=0||x%400==0);
for(k=1;kz=z+tab[n][k];
returnz;
}
(13)程序运行时,输入100000,输出 (13) 。
A、29 B、28 C、0 D、-1
(14)程序运行时,输入001000,输出 (14) 。
A、29 B、28 C、0 D、-1
(15)程序运行时,输入200021200031,输出 (15) 。
A、29 B、28 C、0 D、-1
(16)程序运行时,输入198121198131,输出 (16) 。
A、29 B、28 C、0 D、-1
试题5(每小题3分,共12分)
阅读下列程序并回答问题,在每小题提供的若干可选答案中,挑选一个正确答案。
【程序】
#include
voidmain()
{inta=-1,b=1;
voidf1(intx,inty),f2(int*x,int*y);
voidf3(int*x,int*y),f4(intx,inty);
f1(a,b);
printf("(%d,%d)\n",a,b);
a=-1,b=1;
f2(&a,&b);
printf("(%d,%d)\n",a,b);
a=-1,b=1;
f3(&a,&b);
printf("(%d,%d)\n",a,b);
a=-1,b=1;
f4(a,b);
printf("(%d,%d)\n",a,b);
}
voidf1(intx,inty)
{intt;
t=x;x=y;y=t;
}
voidf2(int*x,int*y)
{intt;
t=*x;*x=*y;*y=t;
}
voidf3(int*x,int*y)
{int*t;
t=x;x=y;y=t;
}
voidf4(intx,inty)
{int*t=malloc(sizeof(t));
*t=x;x=y;y=*t;
}
(17)程序运行时,第1行输出 (17) 。
A、(1,-1)B、(-1,1) C、(-1,-1) D、(1,1)
(18)程序运行时,第2行输出 (18) 。
A、(1,-1)B、(-1,1) C、(-1,-1) D、(1,1)
(19)程序运行时,第3行输出 (19) 。
A、(1,-1)B、(-1,1) C、(-1,-1) D、(1,1)
(20)程序运行时,第4行输出 (20) 。
A、(1,-1)B、(-1,1) C、(-1,-1) D、(1,1)
试题6(每小题3分,共12分)
#include
structcard{
char*face;
char*suit;
};
voidfilldeck(structcard*wdeck,char*wface[],char*wsuit[])
{ inti;
for(i=0;i<4;i++){
wdeck[i].face=wface[i%2];
wdeck[i].suit=wsuit[i/2];
}
}
voiddeal(structcard*wdeck)
{ inti;
for(i=0;i<4;i++)
printf("(%2sof%-6s)\n",wdeck[i].face,wdeck[i].suit);
}
voidmain()
{ structcarddeck[4];
char*face[]={"K","Q"};
char*suit[]={"Heart","Club"};
filldeck(deck,face,suit);
deal(deck);
}
(21)程序运行时,第1行输出 (21) 。
A、(KofHeart)B、(QofHeart)
C、(KofClub) D、(QofClub)
(22)程序运行时,第2行输出 (22) 。
A、(KofHeart)B、(QofHeart)
C、(KofClub) D、(QofClub)
(23)程序运行时,第3行输出 (23) 。
A、(KofHeart)B、(QofHeart)
C、(KofClub) D、(QofClub)
(24)程序运行时,第3行输出 (24) 。
A、(KofHeart)B、(QofHeart)
C、(KofClub) D、(QofClub)
试题7(14分)
编写程序,输入一批学生的成绩,遇0或负数则输入结束,要求统计并输出优秀(大于85)、通过(60~84)和不及格(小于60)的学生人数。
运行示例:
Enterscores:
88716870598191426677830
>=85:
2
60-84:
7
<602
试题8(14分)
编写程序,输入一个正整数n,求下列算式的值。
要求定义和调用函数fact(k)计算k的阶乘,函数返回值的类型是double。
运行示例:
Entern:
5
sum=1.71667
2006年春浙江省高等学校
计算机等级考试答案(二级C)
试题1~6
试题7
试题8
合计
试题1~6
A
B
C
D
A
B
C
D
(1)
√
(13)
√
(2)
√
(14)
√
(3)
√
(15)
√
(4)
√
(16)
√
(5)
√
(17)
√
(6)
√
(18)
√
(7)
√
(19)
√
(8)
√
(20)
√
(9)
√
(21)
√
(10)
√
(22)
√
(11)
√
(23)
√
(12)
√
(24)
√
试题7
#include
voidmain()
{
intmark,a,p,f;
c=p=f=0;
printf("Enterscores:
");
scanf("%d",&mark);
while(mark>=0){
if(mark>=85)a++;
elseif(mark>=60)p++;
elsef++;
scanf("%d",&mark);
}
printf(">=85:
%d\n",a);
printf("60-84:
%d\n",p);
printf("<60:
%d\n",a);
}
试题8
#include
voidmain()
{inti,n;
doublex,sum;
doublefact(intn);
scanf("%d",&n);
sum=0;
for(i=1;i<=n;i++)
sum=sum+1/fact(i);
printf("sum=%f\n",sum);
}
doublefact(intn)
{inti;
doubleres=1;
for(i=1;i<=n;i++)
res=res*i;
returnres;
}
7