试题2008C程序设计考试(非A).doc
20072008学年第二学期 装 订 线 一选择题:(共20分2分×10)有定义:int a=2,b=3,c=8;下面表达式的值不为2的是(D)A)c%b B)c/b C)a+ D)5.8/a能正确表示数学表达式0x10的C语言表达式为(C)A)0<x<10B)!( a<0 ) | !( a>10 )C)( x>0 ) && ( x<10 )D)( x>0 ) | ( x<10 )有定义:int a=1,b=3;表达式a=a+2,a+b的值是(D)A)1B)3 C)4 D)6若int a=2,b=3,x;则执行语句if (a<b) x=a<b;else x=a>b;后x值是(B)A)0B)1C)2 D)3以下程序段执行后m的值是(A)int k=0,m=0;while ( k=5 ) m+;k+;A)0 B)4C)5 D)死循环执行循环语句 for ( x=0,y=0;( x!=3) && ( x<8);x+ ) y+;后y的值是(A)A)3 B)8 C)0D)不确定若有说明:int i,j = 7,*p = &i,*q=&j;则与i = j;不等价的语句是(A)A)p = q; B)*p = *q; C)*&i = *q; D)*p = *&j;若有说明:int a10,*p = a;对数组元素的正确引用是(C)A)a p B)p a C)*( p + 2 ) D)p + 2下面各语句行中,能正确进行字符串操作的语句是(C)A)char a5 = “ABCDE”; B)char s5 = A,B,C, D,E;C)char *s; s = “ABCDEF”; D)char *s; scanf(“%s”,&s);设有如下定义,则对data中的成员a的正确引用是(B)struct sk int a; float b ; data,*p = &data;A)(*p).data.a B)( *p ).a C)p -> data.a D)p.data.a 装 订 线 装 订 线 二阅读程序,写出运行结果:(共40分4分×10)程序1:程序2:void main ( ) int x=3,y=8,z =0;if (x>10) if (y>10) z=1;else z= -1;printf ( “%d”,z );void main ( ) int m=0,s=0;while ( m+ < 4 ) s=s+m;printf ( “%d”,m );运行结果为: 0运行结果为: 5程序3:程序4:void main ( ) int j ,s = 0 ;for ( j=1;j<=10;j+ )if ( j%2 != 0 ) s = s + j;printf ( "%d",s );void main ( ) int k,s=0,a8= 1,2,3,4,5,6,7,8 ;for ( k = 0;k<8;k+ ) s = s + ak;if ( k=3 ) break;printf ( “%d”,s );运行结果为: 25运行结果为: 10程序5:程序6:void main ( )char str = "20080512" ;int k,m=0;for( k=0;strk!='0';k+ ) m+ ;printf ( "%d",m );void main ( ) int a=2,*p=&a,*q;q = p;(*q) +;printf ( “%d”,a );运行结果为: 8运行结果为: 3程序7:程序8:void main ( ) int j,i,s=0;int a33 = 1,2,3,4,5,6,7,8,9 ;for ( i = 0;i<3;i+ )for ( j = 0;j<3;j+ )if ( j < i ) s = s + aij;printf ( “%d”,s );int func ( int n , int m ) int k;for ( k=n;k>0;k - - ) if ( n%k=0 && m%k=0 ) break;return k ; void main ( ) printf ( "%d",func ( 18 , 24 ) );运行结果为: 19运行结果为: 6 装 订 线 程序9:程序10:int func ( int *a,int n,int k ) int i;for ( i=0;i<n;i+ )if ( *( a+i ) = k ) return i;return(-1);void main ( ) int a10 = 3,6,9,0,2,5,8,1,4,7 ;printf ( “%d”,func (a,10,1) );void main ( ) int m;struct student int num;char name10;int score; a2 = 1011,“zhangsan” , 75 , 1012, “Lisi” , 81 ,*p = a; if ( p->score > a1.score ) m=p->sum; else m = (p+1)->sum; printf ( “%d”,m );运行结果为: 7运行结果为: 1012三在下面程序空白处填入适当语句,完成题目要求:(共16分4分×4)程序功能:输出九九乘法口诀表。void main ( ) int i,j; for ( i = 1;i < 10;i+ ) for ( ) printf ( "%d*%d = %- 4d",j,i,i*j ); printf ( "n" )程序功能:输出a数组中最大元素的下标。void main ( ) int k,i;int a6 = 1,-9,7,2,-10,3 ;for ( i = 0,k = i;i < 6;i +) if ( ai > ak ) printf ( “%dn” , k );程序功能:求n×n矩阵上主对角线上元素之和。void main ( ) int a33 = 9,7,5,3,1,2,4,6,8 ;int i,j,s = 0;for ( i = 0;i < 3;i + ) for ( j = 0;j < 3;j + ) printf ( “%dn”,s );函数功能:实现字符串的复制。void strcopy ( char *from,char *to ) char *p;for ( )*to = *p;*to = 0 ;四编写程序:(共24分8分×3)1编写程序,计算并输出一维整型数组a10中所有元素的平均值。2编写函数,函数功能为判断正整数n是否为素数,若n为素数则返回1,否则返回0。3编写函数实现两个整数的交换(提示:通过地址传递方式实现)。