上海市高等学校计算机等级考试二级(C程序设计)
03年上海市高等学校计算机等级考试试卷
二级 (C程序设计)
(本试卷答卷时间为120分钟)
试题一(28分,每小题4分)
解答下列各小题,把正确的解答写在答卷纸的对应栏内。
设有变量说明:
int a=5,b=4,c=3,r1,r2;
请写出执行下列语句后r1和r2的值。
r1=a>b>c;
r2=a>b&&b>c; r1=0 r2=1
试写出下列算式的C语言表达式。
exp(ln(a)/3)*sin(75.0/180*3.14)/fabs(x-ln(y)/ln(2))
执行下列语句后,i,j,k的值是多少?
for (i=k=0,j=6; i
i=3 j=3 k=-63
执行下列程序后,b和c的值各为多少?
#include
void main()
{ int *a[10],b,c;
a[0]=&b;
*a[0]=5;
c=(*a[0])++;
printf(“%d %d\n”,b,c);
}
b=6 c=5
设有如下程序:
#include
void main()
{ int clock; float f; char cpu[20];
scanf(“%4d%f%s”,&clock,&f,cpu);
printf(“%d %.0f %s\n”,clock,f,cpu);
}
假设输入数据流为200015.0 P4 is GOOD!,请写出执行该程序后的输出结果。
2000 15 P4
下列程序的输出结果是什么?
#include
main()
{ int c1=0,c2=0,c3=0,c4=0;
char *p=”12395632123378”;
while (*p)
{ switch (*p)
{ case ‘1’
case ‘2’
case ‘3’
default : c4++;
}
p++;
}
printf(“c1=%d c2=%d c3=%d c4=%d\n”,c1,c2,c3,c4);
}
c1=2 c2=3 c3=7 c4=5
7 执行下列程序后,s的值为多少?
#define sq(X) X*X
void main()
{ int s=15, a=2, b=1;
printf(“s=%d\n”,s=sq(a+b)/sq(a+b));
}
s=7
试题二(12分,每小题6分)
阅读下列程序,把程序的输出结果写在答卷纸的对应栏内。
(1)【程序2.1】
#define N 6
void main()
{ int i,j,a[N];
for ( i=1; i
{ a[i]=1;
for ( j=i-1; j>1; j--)
a[j]+=a[j-1];
for ( j=1; j<=i; j++)
printf(“%4d”,a[j]);
printf(“\n”);
}
}
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
(2)【程序2.2】
#include
void fun(char *s)
{ while (*s)
{ *s= (*s-‘0’+3)%10+’0
++s;
}
}
void main()
{ char a[]=”314762985”
fun(a+3);
for ( i=0; i<3; ++i)
printf(“%c\n”,a[3*i+1]);
}
1
9
1
试题三(12分,每小题6分)
改错。下列程序中都有三个错误,按原来程序的要求,纠正错误,并以“将#XX行改为YYYY”的形式进行解答,代码左边的“#01”、“#02”、…是附加的行号。
程序3.1功能是输入一个字符串,并将其中的字符’a’用字符串”shu”替代后输出。如输入为”123abcaHello”,则输出为”123shubcshuHello”。
【程序3.1】
#01 #include