《C语言程序设计》考试试卷1及答案一、写出以下程序运行的结果(每题5分,共30分)
程序1
#include<stdio.h> main()
{int a,k,n=3;
float b,c;
a=2;k=3;b=4;c=5;
b=a*k+n;
printf("%d,%d\n",a,b); }
程序3
#include<stdio.h> main()
{int k=8;
while(k>0)
if((k-=2)>0) continue; printf("%d\n",k);
}
程序5
#include<stdio.h> main()
程序2
#include<stdio.h>
main()
{int a,b,c=1;
while(c<5)
c++;
a=5;b=6;a=(a++)+(++b);
printf("%d,%d,%d\n",a,b,c);
}
程序4
#include<stdio.h>
main()
{int i;
for(i=2;i<=10;i++)
{if(i%3!=0)
i+=2;
printf("%d,",i);
}
printf("%d\n",i);
}
程序6
#include<stdio.h>
main() //已知字符A的ASCII值是65 {char c;
c=getchar(); //从键盘输入字符E
{int i=0,k=1;
do
{i++;
k=k+i;
printf("%d\t",i);
}while(i<10);
printf("%d\n",k);
}
二、选择题(每题3分,共42分)
1、能正确表示“当x的取值在[1,10]和[200,210]范围内为真,否则为假”的表达式是。
A)(x>=1) && (x<=10) && (x>=200) && (x<=210)
B)(x>=1) | | (x<=10) | | (x>=200) | | (x<=210)
C)(x>=1) && (x<=10) | | (x>=200) && (x<=210)
D)(x>=1) | | (x<=10) && (x>=200) | | (x<=210)
2、设:int a=1,b=2,c=3,d=4,m=2,n=2;执行(m=n>b) && (n=c>d)后n的值为。
A)1 B)2 C)3 D)0
3、下面是错误的if语句(设int x,a,b;)
A)if (a=b) x++; B)if (a=<b) x++;
C)if (a-b) x++; D)if ( x ) x++;
4、下述程序的输出结果是。
main ( )
{ int a=0,b=0,c=0;
if (++a>0 | | ++b>0)
++c;
printf(“%d,%d,%d”,a,b,c); }
A)0,0,0 B)1,1,1 C)1,0,1 D)0,1,1
5、在下面的条件语句中(其中S1和S2表示C语言语句),只有一个在功
能上与其他三个语句不等价。
A)if (a) S1; else S2; B)if (a==0) S2; else S1;
C)if (a!=0) S1; else S2; D)if (a==0) S1; else S2;
6、下面程序段
int k=2;
while (k=0) {printf(“%d”,k);k--;}
则下面描述中正确的是。
A)while循环执行10次B)循环是无限循环
C)循环题语句一次也不执行D)循环体语句执行一次
7、下述程序段的运行结果是。
int a=1,b=2, c=3, t;
while (a<b<c) {t=a; a=b; b=t; c--;}
printf(“%d,%d,%d”,a,b,c);
A)1,2,0 B)2,1,0 C)1,2,1 D)2,1,1
8、下面程序的功能是从键盘输入一组字符,从中统计大写字母和小写字母的
个数,选择填空。
main ( )
{ int m=0,n=0;
char c;
while (( ) ! =‘\n’)
{
if (c>=’A’ && c<=’Z’) m++;
if (c>=’a’ && c<=’z’) n++;
} }
A)c=getchar( ) B)getchar( ) C)c= =getchar( ) D)scanf(“%c”,&c)
9、下列语句中,符合语法的赋值语句是。
A)a=7+b+c=a+7;B)a=7+b++=a+7;
C)a=(7+b,b++,a+7);D)a=7+b,c=a+7;
10、与代数式(x*y)/(u*v) 不等价的C语言表达式是。
A)x*y/u*v B)x*y/u/v C)x*y/(u*v) D)x/(u*v)*y
11、若int k=7,x=12;则能使值为3的表达式是。
A)x%=(k%=5) B)x%=(k-k%5)
C)x%=k-k%5 D)(x%=k)-(k%=5)
12、假定x和y为double型,则表达式x=2,y=x+3/2的值是。
A)3.500000 B)3 C)2.000000 D)3.000000
13、设变量n为float型,m为int类型,则以下能实现将n中的数值保留小
数点后两位,第三位进行四舍五入运算的表达式是。
A)n=(n*100+0.5)/100.0 B)m=n*100+0.5,n=m/100.0
C)n=n*100+0.5/100.0 D)n=(n/100+0.5)*100.0
14、执行下列程序片段时输出结果是。
int x=13,y=5;
printf(“%d”,x%=(y/=2));
A)3 B)2 C)1 D)0
三、程序填空题(每空3分,共9分)
1、输出100~200之间所有的素数,并统计个数。
#include<stdio.h>
#include<math.h>
Main( )
{int n,d,k, ;
For(n=100;n<=200;n++)
{ ;
For(k=2;k<=d;k++)
If(n%k= =0)break;
If (k>=d)
{printf(“%d 是素数\n ”, n);
;
}printf(“素数的个数是:\n ”, m);
} }
四、编程题(10分+9分=19分) 1、求斐波那数列前30项的平均值。
1,1,2,3,5,8,13,…….
一、写出程序运行结果
1、2,0
2、13,7,5
3、0
4、4,7,10,11
5、1 2 3….10
6、D
56
二、选择题
1、C
2、D
3、B
4、B
5、A
6、D
7、B
8、B
9、C 10、D
11、C 12、A 13、C 14、A
三、程序填空题
1、m=0, d=sqrt( n ), m++
四、程序设计题
2、从键盘输入20个数,统计最后一位数字是
奇数(例:247,最后一位是奇数)的个数。