最新中央C语言程序设计模拟试题及解答(亲测)知识点复习考点归纳总结参考.doc_第1页
最新中央C语言程序设计模拟试题及解答(亲测)知识点复习考点归纳总结参考.doc_第2页
最新中央C语言程序设计模拟试题及解答(亲测)知识点复习考点归纳总结参考.doc_第3页
最新中央C语言程序设计模拟试题及解答(亲测)知识点复习考点归纳总结参考.doc_第4页
最新中央C语言程序设计模拟试题及解答(亲测)知识点复习考点归纳总结参考.doc_第5页
免费预览已结束,剩余4页可下载查看

下载本文档

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

文档简介

电大c语言程序设计模拟试题及解答一、选择题 1. 由c语言源程序文件编译而成的目标文件的缺省扩展名为( c )。 a. cpp b. exe c. obj d. c 2. c语言程序的基本模块为( d )。 a. 表达式 b. 标识符 c. 语句 d. 函数 3. 设x和y均为逻辑值,则x|y为假的条件是( c )。 a它们均为真 b.其中一个为真 c.它们均为假 d.其中一个为假 4. x0 | y=5的相反表达式为( b )。a. x=0 | y!=5 b. x0 | y!=5 d. x0 & y=5 5. 枚举类型中的每个枚举常量的值都是一个( a )。 a. 整数 b. 浮点数 c. 字符 d. 逻辑值6. 循环体至少被执行一次的语句为( c )循环语句。 afor b.while c.do-while d.任一种 7. 循环语句“for(int i=0; in; i+) s;”中循环体s被执行的次数为( c )。 a. 1 b. n-1 c. n d. n+1 8. 在下面的while循环语句中,其循环体被执行的次数为( c )。 int i=0,s=0; while(s3 & x10的相反表达式为 x=10 。 17若x=5,y=10,则x!=y的逻辑值为 1 。 18. 假定x=5,则执行“int a=(! x? 10:20);”语句后a的值为 20 。19. 在if语句中,每个else关键字与它前面同层次并且最接近的 if 关键字相配套。 20. 若while循环的“头”为“while(i+name等价的表达式是 (*p).name 。三、写出下列每个程序运行后的输出结果 1. #include void main() int i, s=0; for(i=1;i+) if(s50) break; if(i%2=0) s+=i; printf(i,s=%d, %dn,i,s); 结果:i,s=15,56 2. #include void main() 结果* char ch=*; int i, n=5; while(1) for(i=0;in;i+) printf(%c,ch); printf(n); if(-n=0) break; 3. #includeconst int n=5;void main()结果 1 1 1 2 2 2 3 6 9 4 24 33 int i,p=1,s=0; for(i=1;in;i+) p=p*i; s=s+p; printf(%5d%5d,i,p); printf(%5dn,s); 4. #include void main() int x=24,y=88; int i=2,p=1; do while(x%i=0 & y%i=0) p*=i; x/=i; y/=i; i+; while(x=i & y=i); printf(%dn,p*x*y); 结果:p*x*y=8*3*11=264 5. #include void main() int a9=36,25,48,24,55,40,18,66,20; int i, b1, b2; a0=a1? (b1=a0, b2=a1):(b1=a1,b2=a0); for(i=2; i9; i+) if(aib1) b2=b1; b1=ai; else if(aib2) b2=ai; printf(%d %dn,b1,b2); 结果:18 20 6. #include void main() int a12=76,63,54,62,40,75,80,92,77,84,44,73; int b4=60,70,90,101; int c4=0; int i,j; for(i=0;i=bj) j+; cj+; for(i=0;i4;i+) printf(%d,ci); printf(n); 结果:3 2 6 17. #include void main() int a=10, b=20;结果 10 20 40 35 40 20 printf(%d %dn,a,b); int b=a+25; a*=4; printf(%d %dn,a,b); printf(%d %dn,a,b); 8. #include void selectsort(int a, int n) int i,j,k,x; for(i=1;in;i+) /进行n-1次选择和交换 k=i-1; for(j=i;jn;j+) if(ajak) k=j; x=ai-1; ai-1=ak; ak=x; void main() int i; int a6=20,15,32,47,36,28; selectsort(a,6); for(i=0; i6; i+) printf(%d ,ai); printf(n); 结果:15 20 28 32 36 47 9#include void main() int a8=4,8,12,16,20,24,28,32; int *p=a; do printf(%d,*p); p+=2; while(pa+8); printf(n); 结果:4 12 20 28 10. #include void le(int* a, int* b) int x=*a; *a=*b; *b=x; 结果15 26 26 15 void main() int x=15, y=26; printf(%d %dn,x,y); le(&x,&y); printf(%d %dn,x,y); 11. #include #include struct worker char name15; /姓名 int age; /年龄 float pay; /工资 ; int equal(struct worker* r1, struct worker* r2) if(strcmp(r1-name, r2-name)=0) return 1; else return 0; void main() struct worker a4=abc,25,420,defa,58,638, ghin,49,560,jklt,36,375; struct worker x=defa; int i; for(i=0; i=4) printf(没有查找所需要的记录!n); else printf(%s %d %6.2fn,,ai.age,ai.pay); 结果:defa 58 638.00四、写出下列每个函数的功能 1. int se(int n) /n为大于等于1的整数 int x,s=0; printf(输入%d个整数: ,n); scanf(%d,&x); if(n=1) return x; s=x; while(-n) scanf(%d,&x); s+=x; return s; 函数功能:求出键盘上输入的n个整数之和并返回。2. float fh() float x,y=0,n=0;scanf(%f,%x);while(x! =-1.0) n+; y+=x;scanf(%f,%x);if(n-0) return y; else return y/n; 函数功能:求出从键盘上输出的一批常数的平均值,以-1.0作为结束输入的标志。 3. #include void wa(int a, int n) int i,k,j,x; for(i=0;in-1;i+) k=i; for(j=i+1;jak) k=j; x=ai; ai=ak; ak=x; 函数功能:采用选择排序的方法对数组a中的n个整数按照从大到小的次序重新排列。 4. #include int* lj(int a, int n) int i,k=0; for(i=1;iak) k=i; return &ak; 函数功能:求出数组a中n个元素的最大值元素,返回该元素的地址。 5. void qc(struct strnode* f) while(f) printf(%sn,f-name);f=f-next; 假定结构类型strnode的定义如下: stuct strnode char name15; /字符串域 struct strnode *next; /指针域 ; 函数功能:遍历f单链表,即从头结点开始依次输出f单链表中每个结点的值。 6. int output(struct intnode *f) int sum=0; if(!f) return -9999; /用返回特定值-9999表示空表 while(f) sum+=f-data; f=f-next; return sum; 假定struct intnode的类型定义为: struct intnode int data; /结点值域 struct intnode* next; /结点指针域 ; 函数功能:对于以表头指针为f的链表,求出并返回所有结点中data域的值之和。 7. int wr4(file* fptr) char ch; int c=0; fseek(fptr,0,seek_set); while(1) ch=fgetc(fptr); if(ch!=eof) c+; else break; return c; 函数功能:求出一个以fptr为文件流的所对应文件的长度,即所存字符的个数。五、根据下列每个题目要求编写程序1. 编写一个函数fun(),首先从键盘上输入一个4行4列的一个实数矩阵到一个二维数组a44中,接着求出主对角线上元素之和,最后返回求和结果。 #include double fun() double a44; double s=0; int i,j; printf(输入一个4*4的数值矩阵:n); for(i=0;i4;i+) for(j=0;j4;j+) scanf(%lf,&aij); for(i=0;i4;i+) s+=aii;i return s; void main() printf(主对角线上元素之和是%lfn,fun(); 2. 编写一个主函数,计算1+3+32+.+310的值并输出,假定分别用i,p,s作为循环变量、累乘变量和累加变量的标识符。#include void main() int i; /用i作为循环变量 int p=1; /用p作为累乘变量 int s=1;

温馨提示

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

评论

0/150

提交评论