C语言程序设计课程期末复习练习小抄参考

上传人:1888****888 文档编号:36842412 上传时间:2021-11-01 格式:DOC 页数:11 大小:191.52KB
收藏 版权申诉 举报 下载
C语言程序设计课程期末复习练习小抄参考_第1页
第1页 / 共11页
C语言程序设计课程期末复习练习小抄参考_第2页
第2页 / 共11页
C语言程序设计课程期末复习练习小抄参考_第3页
第3页 / 共11页
资源描述:

《C语言程序设计课程期末复习练习小抄参考》由会员分享,可在线阅读,更多相关《C语言程序设计课程期末复习练习小抄参考(11页珍藏版)》请在装配图网上搜索。

1、专业好文档C语言程序设计课程期末复习练习 一、单选题 1在每个C语言程序中都必须包含有这样一个函数,该函数的函数名为( )。 A. main B. MAIN C. name D. function 2每个C语言程序文件的编译错误分为( )类。 A. 1 B. 2 C. 3 D. 4 3. 字符串a+b=12n的长度为( )。 A. 6 B. 7 C. 8 D. 9 4. 在switch语句的每个case块中,假定都是以break语句结束的,则此switch语句容易被改写为( )语句。 A. for B. if C. do D. while 5. 在下面的do-while循环语句中,其循环体语句

2、被执行的次数为( )。 int i=0; do i+; while(i10); A. 4 B. 3 C. 5 D. 10 6. 将两个字符串连接起来组成一个字符串时,选用的函数为( )。 A. strlen() B. strcap() C. strcat() D. strcmp() 7. 若用数组名作为函数调用的实参,传递给形参的是( )。 A. 数组的首地址 B. 数组中第一个元素的值 C. 数组中全部元素的值 D. 数组元素的个数 8. 假定a为一个整数类型的数组名,整数类型的长度为4,则元素a4的地址比a数组的首地址大( )个字节。 A. 4 B. 8 C. 16 D. 32 9. 假定

3、s被定义为指针类型char *的变量,初始指向的字符串为Hello world!,若要使变量p指向s所指向的字符串,则p应定义为( )。 A. char *p=s; B. char *p=&s; C. char *p;p=*s; D. char *p; p=&s; 10. 从一个数据文件中读入以换行符结束的一行字符串的函数为( )。 A. gets() B. fgets() C. getc() D. fgetc() 11. 由C语言目标文件连接而成的可执行文件的缺省扩展名为( )。 A. cpp B. exe C. obj D. c 12. 设有两条语句为“int a=12; a+=a*a;”

4、,则执行结束后,a的值为( )。 A. 12 B. 144 C. 156 D. 288 13. 带有随机函数调用的表达式rand()%20的值在( )区间内。 A. 119 B. 120 C. 019 D. 020 14. for循环语句“for(i=0; i0 & x=10)的相反表达式为( )。A. x10 B. x10C. x=0 | x0 & x10 23. 当处理特定问题时的循环次数已知时,通常采用( )循环来解决。 A. for B. while C. do-while D. switch 24. 假定i的初值为0,则在循环语句“while(ib | b=5的相反表达式为_。 6.

5、 执行“typedef int DataType;”语句后,在使用int定义整型变量的地方也可以使用_来定义整型变量。 7. 假定一维数组的定义为“char* a8;”,则该数组所占存储空间的字节数为_。 8. 假定二维数组的定义为“double aMN;”,则该数组的列下标的取值范围在_之间。 9. 存储一个空字符串需要占用_个字节。 10. strcpy函数用于把一个字符串_到另一个字符数组空间中。 11. 程序的编译单位是一个_。 12. 假定a是一个一维数组,则ai的指针访问方式为_。 13. 执行int *p=malloc(sizeof(int)操作得到的一个动态分配的整型对象为_。

6、 14执行“printf(%c,A+2);”语句后得到的输出结果为_。 15short int类型的长度为_。 16. 用类型关键字表示十进制常数3.26f的类型为_。 17. 假定y=10,则表达式+y*3的值为_。 18. 逻辑表达式(x=0 & y5)的相反表达式为_。 19若x=5,y=10,则x!=y的逻辑值为_。 20. 假定二维数组的定义为“int a35;”,则该数组所占存储空间的字节数为_。 21. 使用“typedef char BB1050;”语句定义_为含有10行50列的二维字符数组类型。 22. 字符串a:xxk数据的长度为_。 23假定p所指对象的值为25,p+1所

7、指对象的值为46,则*+p的值为_。 24. 假定一个数据对象为int*类型,则指向该对象的指针类型为_。 25假定一个结构类型的定义为 “struct Aint a,b; A* c;”,则该类型的长度为_。 26. 假定要访问一个结构对象x中的数据成员a,则表示方式为_。 27. 用于输出表达式值的标准输出函数的函数名是_。 28每个C语言程序文件在编译时可能出现有致命性错误,其对应的标识符为_。 29. 已知AZ的ASCII码为6590,当执行“int x=C+3;”语句后x的值为_。 30. 表达式(int)14.6的值为_。 31. 假定不允许使用逻辑非操作符,则关系表达式x+y5的相

8、反表达式为_。 32. 假定x=5,则执行“a=(x?10:20);”语句后a的值为_。 33. 假定一维数组的定义为“char* aM;”,则该数组所占存储空间的字节数为_。 34. 存储字符串a需要至少占用存储器的_个字节。 35. strlen()函数用于计算一个字符串的_。 36. 在C语言中,一个函数由函数头和_这两个部分组成。 37假定p所指对象的值为25,p+1所指对象的值为46,则执行表达式*(p+)后,p所指对象的值为_。 38. 假定p是一个指向整数对象的指针,则用_表示指针变量p的地址。 39. 与结构成员访问表达式p-name等价的访问表达式为_。参考解答:1. ;(或

9、分号) 2. # 3. void 4. 0x195. a=b & b!=5 6. DataType 7. 32 8. 0N-19. 1 10. 拷贝(复制) 11. 程序文件 12. *(a+i)13. *p 14. C 15. 2 16. float17. 33 18. (x!=0 | y=5) 或:(x | y=5) 19. 1 20. 60 21. BB 22. 1123. 46 24. int* 25. 12 26. x.a27. printf 28. error 29. 70 30. 1431. x+y=5 32. 10 33. 4*M 34. 235. 长度 360. 函数体 37

10、. 46 38. &p39. (*p).name 三、写出下列每个程序运行后的输出结果 1. #include void main() int x=5; switch(2*x-1) case 4: printf(%d ,x); break; case 7: printf(%d ,2*x); break; case 10: printf(%d ,3*x); break; default: printf(%s ,default); printf(%sn,switch end.); 2. #include void main() int f1,f2,i; f1=1; printf(%d ,f1);

11、for(i=2;i=5;i+) f2=3*f1+1; printf(%d ,f2); f1=f2; printf(n); 3. #include void main() int a10=12,39,26,41,55,63,72,40,83,95; int i, i1=0, i2=0; for(i=0;i10;i+) if(ai%2=1) i1+; else i2+; printf(%d %dn,i1,i2); 4. #include #include void main( ) char s15=567891234; int i, n=strlen(s) ; for(i=0; in/2; i+)

12、 char c=si; si=sn-1-i; sn-1-i=c; printf(%sn,s); 5. #include int LB(int *a, int n) int i,s=1; for(i=0;in;i+) s*=*a+; return s; void main() int a=1,2,3,4,2,4,5,2; int b=LB(a,4)+LB(a+3,3); printf(b=%dn,b); 6. #include void main() int i,s=0; for(i=1;i6;i+) s+=i*i; printf(“s=%dn”,s); 7. #include #define

13、N 6 void main() int i,aN=2,5,8,10,15,21; for(i=0; iN; i+) if(ai%5) printf(%d ,ai); printf(n); 8. #include #include void main() int i; unsigned int len; char* a5=student,worker,cadre,soldier,zzeasan123; len=strlen(a0); for(i=1; ilen) len=strlen(ai); printf(%dn,len); 9. #include void main() int a,b; f

14、or(a=2,b=3; b20;) printf(%d %d ,a,b); a=a+b; b=a+b; printf(%d %dn,a,b); 10. #include void LE(int* a, int* b) int x=*a; *a=*b; *b=x; void main() int x=15, y=26; printf(%d %dn,x,y); LE(&x,&y); printf(%d %dn,x,y); 11. #include void main() int i, s=0; for(i=1;i+) if(s30) break; if(i%2=0) s+=i; printf(s=

15、%dn,s); 12. #include void main() int a9=36,25,48,24,55,40,18,66,20; int i, b1, b2; b1=b2=a0; for(i=1; ib1) b1=ai; if(aib2) b2=ai; printf(%d %dn,b1,b2); 13. #include void SB(char ch) switch(ch) case A: case a: printf(WW ); break; case B: case b: printf(GG ); break; default: printf(BB ); break; void m

16、ain() char a1=a,a2=B,a3=f; SB(a1);SB(a2);SB(a3); printf(n); 14. #include #define M 6 void main() int i,x; int aM=10,15,22,37,46,58; for(i=0; iM/2; i+) x=ai; ai=aM-1-i; aM-1-i=x; for(i=0; i6; i+) printf(%d ,ai); printf(n); 15. #include struct Worker char name15; int age; float pay; ; void main() stru

17、ct Worker x=wanghua,52,2350; struct Worker y, *p; y=x; p=&x; printf(%d %7.2fn, y.age+p-age, p-pay+20); 16. #include void main() int i,j,k=0; for(i=0; i5; i+) for(j=i; j5; j+) k+; printf(%dn,k); 17. #include void main() int x=60; int i=2, p=1; while(1) if(x%i=0) p*=i; x/=i; if(ix) i+; else break; pri

18、ntf(%dn,p); 18. #include void main() int a8=76,63,54,62,40,75,90,58; int i; for(i=0; i70) printf(%d ,ai); printf(n); 19. #include void WF(int x, int y) x=x+y; y+=x; printf(%d %dn,x,y); void main() int x=3, y=8; WF(x,y); 20. #include int LA(int *a, int n) int i,s=0; for(i=0;in;i+) s+=ai; return s; vo

19、id main() int a5=3,4,6,10,20; int b=LA(a,5); int c=LA(a+2,3); printf(%d %dn,b,c); 参考解答: 1. default switch end. 2. 1 4 13 40 121 3. 6 4 4. 432198765 5. b=56 6. s=55 7. 2 8 21 8. 10 9. 2 3 5 8 13 21 10. 15 26 26 15 11. s=42 12. 66 18 13. WW GG BB 14. 58 46 37 22 15 10 15. 104 2370.00 16. 15 17. 30 18.

20、 76 75 90 19. 11 19 20. 43 36 四、写出下列每个函数的功能 1. #include int SG(int x) /x为大于等于2的整数 int a=(int)sqrt(x); /sqrt(x)取x的平方根 int i=2; while(i=a) if(x%i=0) break; i+; if(idata; f=f-next; while(f) if(f-datax) x=f-data; f=f-next; return x; 假定struct IntNode的类型定义为: struct IntNode int data; struct IntNode* next;

21、3. #include int SA(int a, int b) if(ab) return 1; else if(a=b) return 0; else return -1; 4. void Output(struct IntNode *f) /f为单链表的表头指针 if(!f) return; while(f) printf(%d ,f-data); f=f-next; printf(n); 假定struct IntNode的类型定义为: struct IntNode int data; struct IntNode* next; 5. int SC(int a, int b, int c

22、) if(a=b & a=c) return a; if(b=a & b=c) return b; return c; 6. int* LI(int n) int* a=malloc(n*sizeof(int); int i; for(i=0;in;i+) scanf(%d,a+i); return a; 7. int WC(int a, int n, int k) int i, c=0; for(i=0;i=k) c+; return c; 8. void QA(struct Worker a, int n) int i; for(i=0; ib则返回1,若a=b则返回0,若ab则返回-1。

23、 4. 遍历并输出由f所指向的单链表中每个结点的值。 5. 求出a,b,c三个数中的最大值并返回。 6. 首先建立一个动态整型数组an,接着从键盘上输入n个整数到an中,最后返回数组an的首地址。 7. 统计并返回一维整型数组an中大于等于k的值的个数。 8. 从键盘上为具有struct Worker类型的数组an输入n个记录。 五、按题目要求编写程序或函数 1. 编写一个程序,输出50以内(含50)的、能够被3或者5整除的所有整数。 2. 编写一个递归函数“int FF(int a, int n)”,求出数组a中所有n个元素之积并返回。 3. 编写一个程序,利用while循环,计算并打印输出

24、的值,其中正整数n值由键盘输入。假定求和变量用sum表示,计数变量用i表示,sum、i和n均定义为全局变量,sum和i的初值分别被赋予0和1。 4. 根据函数原型“void DD(int a, int n, int MM)”编写函数定义,利用双重循环查找并打印输出数组an中任何两个元素的值等于MM值的元素值。假定ai+aj等于MM,则输出格式为:(ai,aj)。 5. 编写一个程序,计算1+3+32+.+310的值并输出,假定分别用i,p,s作为循环变量、累乘变量和累加变量的标识符。 6. 根据函数原型“int FF(int a, int n)”,编写函数定义,计算并返回数组an中所有元素之和

25、。 7. 根据函数原型“double Mean(double aMN,int m,int n)”,编写函数定义,要求返回二维数组amn中所有元素的平均值。假定在计算过程中采用变量v存放累加值和最后的平均值。 8. 根据函数原型“int MM(int a,int m)”,编写函数定义,计算并返回数组am中元素最大值和最小值之差。 参考解答: 1. #include void main() int i; for(i=3; i=50; i+) if(i%3=0 | i%5=0) printf(%d ,i); printf(n); 2. int FF(int a, int n) if(n=0) pri

26、ntf(n值非法n),exit(1); if(n=1) return an-1; else return an-1*FF(a,n-1); 3. #include int n,i=1; double sum=0; void main() scanf(%d,&n); while(i=n) sum+=(double)1/i+; printf(sum=%lfn,sum); 4. void DD(int a, int n, int MM) int i,j; for(i=0; in; i+) for(j=i+1; jn; j+) if(ai+aj=MM) printf(%d, %dn, ai,aj); 5

27、. #include void main() int i; int p=1; int s=1; for(i=1;i=10;i+) p*=3; s+=p; printf(%dn,s); 6. int FF(int a, int n) int i,sum=0; for(i=0; in; i+) sum+=ai; return sum; 7. double Mean(double aMN,int m,int n) int i,j; double v=0.0; for(i=0; im; i+) for(j=0; jn; j+) v+=aij; v/=m*n; return v; 注:函数体的最后两行可

28、以合并为一条返回语句:return v/=m*n 8. int MM(int a,int m) int i,x1,x2; x1=x2=a0; for(i=1; ix1) x1=ai; if(aix2) x2=ai; return x1-x2; If we dont do that it will go on and go on. We have to stop it; we need the courage to do it.His comments came hours after Fifa vice-president Jeffrey Webb - also in London for t

29、he FAs celebrations - said he wanted to meet Ivory Coast international Toure to discuss his complaint.CSKA general director Roman Babaev says the matter has been exaggerated by the Ivorian and the British media.Blatter, 77, said: It has been decided by the Fifa congress that it is a nonsense for rac

30、ism to be dealt with with fines. You can always find money from somebody to pay them.It is a nonsense to have matches played without spectators because it is against the spirit of football and against the visiting team. It is all nonsense.We can do something better to fight racism and discrimination

31、.This is one of the villains we have today in our game. But it is only with harsh sanctions that racism and discrimination can be washed out of football.The (lack of) air up there Watch mCayman Islands-based Webb, the head of Fifas anti-racism taskforce, is in London for the Football Associations 15

32、0th anniversary celebrations and will attend Citys Premier League match at Chelsea on Sunday.I am going to be at the match tomorrow and I have asked to meet Yaya Toure, he told BBC Sport.For me its about how he felt and I would like to speak to him first to find out what his experience was.Uefa haso

33、pened disciplinary proceedings against CSKAfor the racist behaviour of their fans duringCitys 2-1 win.Michel Platini, president of European footballs governing body, has also ordered an immediate investigation into the referees actions.CSKA said they were surprised and disappointed by Toures complai

34、nt. In a statement the Russian side added: We found no racist insults from fans of CSKA.Baumgartner the disappointing news: Mission aborted.The supersonic descent could happen as early as Sunda.The weather plays an important role in this mission. Starting at the ground, conditions have to be very ca

35、lm - winds less than 2 mph, with no precipitation or humidity and limited cloud cover. The balloon, with capsule attached, will move through the lower level of the atmosphere (the troposphere) where our day-to-day weather lives. It will climb higher than the tip of Mount Everest (5.5 miles/8.85 kilo

36、meters), drifting even higher than the cruising altitude of commercial airliners (5.6 miles/9.17 kilometers) and into the stratosphere. As he crosses the boundary layer (called the tropopause),e can expect a lot of turbulence.The balloon will slowly drift to the edge of space at 120,000 feet ( Then, I would assume, he will sl

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

copyright@ 2023-2025  zhuangpeitu.com 装配图网版权所有   联系电话:18123376007

备案号:ICP2024067431-1 川公网安备51140202000466号


本站为文档C2C交易模式,即用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知装配图网,我们立即给予删除!