C语言考试题正题_第1页
C语言考试题正题_第2页
C语言考试题正题_第3页
C语言考试题正题_第4页
C语言考试题正题_第5页
已阅读5页,还剩7页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、一、单项选择题(每题1分,共20分)请将正确选项写在下表相应位置上,答在其他位置不得分。12345678910111213141516171819201以下哪个符号在传统流程图中表示“判断框”( )。A B C D2在C语言中用( )代表“真”。A0B非0数CtrueDTRUE3整形数x和y的初始值为int x = 3,y=2; 则表达式x<y ? x+ : y+;执行后x和y的值为 ( )。Ax=3, y=2 Bx=4, y=3Cx=4, y=2Dx=3, y=34下面哪个数据类型不属于基本类型( )。AintBfloat Cenum Dsigned int5以下程序运行后,输出结果是

2、( )。#define POWER(X) X*Xint main() int a = 2, b =2; printf(“%d”, POWER(a+b); return 0; A8 B16 C12 D46下面哪个变量名的命名是非法的( )。A3YearNoB_iTotalCiIndex_1_2_3DuMonth7下面程序的输出是( )。#include<stdio.h>int main() int k = 1, i = 3, n; n = (k += i *= k); printf("n = %d, i = %dn", n, i); return 0;An=4,

3、i=3Bi=3, n=4Cn=16, i=3Dn=4, i=48已知字符A的ACSII码值为65,以下语句的输出结果是( )。char ch = B;printf(“%c, %on”, ch, ch);A. B, 66B. B, BC. B, 102D. A, B9表达式(x>y>0)等价于( )。A(x>y) && (y>0) Bx>0&&y>0Cx>0|y>0Dx>y10有“C语言之父”之称的下面哪一位( )。A. Dennis M. Ritchie ;B. Ken Thompson ;C. Alan J

4、. Perlis; D. Alan Turning;11声明数组int a4; 下面哪条语句操作是错误的( )。Aa2 = 3; Bscanf(“%d”, &a);Cscanf(“%d”, &a2); Dprintf(“%d”,a0);12若二维数组a有x行,y列,则在aij之前的元素个数为( )。Aj*x+i Bi*y+jCi*x+y-1Di*y+j-113有如下程序:int f(int x) int y; if(x=0|x=1) return (3); y=x*x-f(x-1); return y;int main() int z; z = f(3); printf(“%d

5、n”,z); return 0; 程序的运行结果是A. 0 B. 9 C. 6 D. 814如下程序:struct A int a; char b10; double c; struct A f(struct A t); int main() struct A a = 1001,"ZhangSan", 98.0;a=f(a);printf("%d,%s,%6.1fn",a.a,a.b,a.c); return 0; struct A f(struct A t) t.a=1002; strcpy(t.b,"LiSi"); t.c=92.

6、0; return t; 程序运行后的输出结果是:A. 1001,ZhangSan,98.0 B. 1002,ZhangSan,92.0 C. 1001,LiSi,98.0 D. 1002,LiSi,92.0 15定义一个3行4列的二维整型元素数组a正确的方式是( )。A. int a43; B. int a3,4; C. int a34; D. int * a34;16下面哪个运算符表示”位与”运算符A&& B| C& D17以"只读"方式打开位于D盘根目录的文件a.dat,下列语句中哪一个是正确的()。Afp=fopen("d:a.da

7、t","a"); Bfp=fopen("d:a.dat","a"); Cfp=fopen("d:a.dat","r"); Dfp=fopen("d:a.dat","r");18. 已知:int b2 = 1, 2, y = 0; int *p=b;,则执行语句y=*p+; 之后,变量y的值为( )。A1B2C3D019下面哪个语句是函数的原型声明A. f( a , b)B. int f(int a , 5);C. int f(int a , in

8、t b); D. int f(int a=5, int b=6);20 下面程序将输出:( )。void fun(int a, int* b) a+;(*b)+; return;int main() int x, y; x=2; y=3; fun(x, &y); printf("%d, %d", x, y);A2,3B3,4C2,4D3,3二、填空题(每空2分,共30分)请将正确选项写在下表相应位置上,答在其他位置不得分。1234567891011121314151以下程序运行后,输出结果是 1 。#include<stdio.h> int main()

9、 intc=0,k;for(k=1;k<3;k+)switch(k)default:c+=k;case 2:c+;case 4:c+=2; printf("%dn",c); return 0  2C语言程序的三种基本结构是 2 。3下面这段程序运行的结果是: 3 。void swap(int* x,int* y)*x = *x *y; *y = *y *x; *x = *x *y; int main() int a = 3, b = 4;swap(&a, &b); printf("a = %d, b = %dn", a,

10、b);return 0;4下面这段程序运行的结果是: 4 。void sum(int *a) a0+=a1;int main() int aa10=1,2,3,4,5,6,7,8,9;int i; for(i=3;i>=0;i-) sum(&aai); printf("%dn",aa0);return 0; 5有以下程序,执行后输出结果是 5 。int main() unsigned char a, b; a = 4 | 1; b = 4 | 0; printf("a=%d,b= %dn",a,b); return 0;6有如下程序,其中的

11、“defau1t”的“1”实际上是数字1不是字母L,这样的情况下当程序运行后键盘输入3后回车,程序输出结果是 6 。#include<stdio.h>int main() int iToTest;scanf("%d", &iToTest);switch(iToTest)case 1:printf("what you input is 1.n");break;case 2:printf("what you input is 2.n"); break;defau1t:iToTest+; break; printf(&q

12、uot;iToTest = %dn", iToTest);return 0;7下列程序的运行结果是 7 。#include <stdio.h>int main() int i,j,x; i=8; j=9; if(+i<j) x = 1; else x = 0; printf("%dn", x); return 0;8下列程序的运行结果是 8 。int main () int a = 3;int b = 3;if ( 2 = = a && +b)a = a + 1; if ( 3 = = a | +b) a = a + 1; pri

13、ntf("a=%i, b=%in", a,b);return 0;9已知 int a=4, b=20; 则(a+3)/3+a%b的值为: 9 。10如下的流程图说明程序是在完成什么事情 10 。 11输入两个正整数m和n,求其最大公约数和最小公倍数。请将程序填完整。int main( )int p, r, n, m, temp;scanf(“%d,%d”,&n,&m);if(n<m) 11 ; 12 ; 13 ;p=n*m;while(m!=0) r=n%m;n=m;m=r;printf(“最大公约数为:%dn”, n);printf(“最小公倍数为:

14、%dn”,p/n);return 0;12. 下面的程序将大写字母变为小写字母字,请将程序填完整。#include <stdio.h>int main () char ch = 'A'ch = ( 14 ) ? (ch+32) : 15 ;printf("ch = %cn", ch);return 0;三、程序阅读题(每题3分,共18分)请将下列各程序的功能或结果写在下表相应位置上,答在其他位置不得分。1234561int max2(int x, int y) int z if(x>y) z = x else z = y

15、 return z int max3(int x, int y, int z) int max max = max2(x, y) if(max < z) max = z return max;int main() int x, y, z,max; scanf(“%d,%d,%d”, &x,&y,&z);max = max3(x,y,z)  printf("max = %dn",max);return 0 2#include <stdio.h>int main()i

16、nt a3 = 1,2,3, 4,5,6;int b32, iRow, iCol;for (iRow = 0; iRow <= 1; iRow+)for (iCol = 0; iCol <= 2; iCol+)biColiRow = aiRowiCol; return 0; 3#include <stdio.h>int main()int a10;int i,j,t;printf("input 10 numbers :n");for (i=0;i<10;i+)scanf("%d",&ai);printf("

17、n");for(j=0;j<9;j+)for(i=0;i<9-j;i+)if (ai>ai+1)t=ai;ai=ai+1;ai+1=t;printf("the sorted numbers :n");for(i=0;i<10;i+)printf("%d ",ai);return 0;4#include <stdio.h>#include <stdlib.h>int main(void) FILE *fp; char ch, filename10; printf("Please input

18、 the file name you want to creat: "); scanf("%s", filename); if(fp = fopen(filename, "w") = = NULL) printf("cannot open filen"); exit(0);/ 终止程序 ch = getchar(); / 接收输入的第一个字符 ch = getchar(); while(ch != '#') fputc(ch, fp); ch = getchar(); fclose(fp); return 0

19、;5#include<stdio.h>#include <math.h>int main() float a,b,c,s,s1;scanf(“%f%f%f”, &a,&b,&c);s=(a+b+c)/2;s1=s*(s-a)*(s-b)*(s-c);s= sqrt(s1);printf(“%fn”,s);return 0;6#include <string.h>#include <stdio.h>struct person char name20; int count;struct person Candidate2 =

20、"Li",0, "Zhang",0; int main() int i,j; char Candidate_name20; printf("Please input the candidate name n type 'exit' stop!n"); do scanf("%s", Candidate_name); for(j = 0; j < 2; j+) if(0 = = strcmp(Candidate_name, C) Candidatej.count+;wh

21、ile(0 !=strcmp(Candidate_name, exit"); if(Candidate0.count > Candidate1.count) printf("The winner is Lin"); else printf("The winner is Zhang"); return 0;四、程序改错(每空2分,共6分)请将正确选项写在下表相应位置上,答在其他位置不得分。每题有1处错误并修改之。1231#include <stdio.h>int main()float a10=0.0;int i;for(i=0

22、;i<3;i+) scanf("%d",&ai); for(i=1;i<10;i+) a0=a0+ai;printf("%fn",a0);return 0;2#include <stdio.h>int main() int x, y; printf( “Please input tow number : ” ) ; scanf(“%d, %d”, &x, &y); if(x = y)printf(“You input the same number”) ; else printf(“You input tw

23、o different number”); return 0;3. / 判断输入的10个数是否全是偶数#include<stdio.h>int main()int a10 = 0;int i;for(i=0;i<10;i+) scanf(“%d,”, &ai);for(i=0;i<10;i+) if(ai%2 != 0) continue;if(i<10) printf(“You input have odd number”);else printf(“You input have no odd number”);return 0;五、编程题(共26分)1

24、(10分)请用指针方式实现复制一个字符串的功能。 7, 8, 910,11,12 1,23,45,62(16分)编程实现矩阵 和 的相乘,要求输出结果。   参考答案:一、单项选择题(每题1分,共20分)1234567891011121314151617181920ABDCAAACDABBDDCCDACC二、填空题(每空2分,共30分)172顺序、选择、循环3a=4, b=34155a=4,b=16iToTest = 3708a=4,b=39610计算5!11. temp = n12. n = m 13.m= temp14 ch>=A&&a

25、mp;ch<=Z15. ch三、程序阅读题(每题3分,共18分)1求三个数的最大数2矩阵转置3输入10个数,用冒泡法进行排序4创建一个文件,向文件中输入字符,直到输入一个“#”为止5由键盘输入三个数a,b,c,计算以这三个数为边长的三角形面积6统计两位候选人的选票数,输出谁得的选票最多四、程序改错(每空2分,共6分)1scanf("%d",&ai);改为scanf("%f",&ai);2if(x = y) 改为if(x = =y)3continue;改为break;五、编程题(共26分)1(10分)请用指针方式实现复制一个字符串的功

26、能。 #include <stdio.h>int main() void copy_string(char *from, char *to); char char_Arrayfrom = "I am a teacher." char char_Arrayto = "you are a student." char *pointer_charfrom = char_Arrayfrom; char *pointer_charto = char_Arrayto; copy_string(pointer_charfrom, pointer_charto); printf("nstring from = %snstring to = %sn", pointer_charfrom, pointer_charto);return 0; void copy_string(char *from, char *to) for (; *from != '0' from+, to+) *to = *from; *t

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论