中央电大C语言程序设计模拟试题及解答(亲测)小抄参考_第1页
中央电大C语言程序设计模拟试题及解答(亲测)小抄参考_第2页
中央电大C语言程序设计模拟试题及解答(亲测)小抄参考_第3页
中央电大C语言程序设计模拟试题及解答(亲测)小抄参考_第4页
中央电大C语言程序设计模拟试题及解答(亲测)小抄参考_第5页
已阅读5页,还剩6页未读 继续免费阅读

下载本文档

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

文档简介

1、专业好文档2012春电大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. 整数

2、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的值为 2

3、0 。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

4、;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

5、=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,

6、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 selectsor

7、t(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 *

8、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; /工资

9、 ; 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); 结

10、果: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 retur

11、n 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个元素的最大值元素,返回该元素的地址。

12、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;

13、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为文件流的所对应文件的长度,即所存字符的个

14、数。五、根据下列每个题目要求编写程序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. 编写一个主函

15、数,计算1+3+32+.+310的值并输出,假定分别用i,p,s作为循环变量、累乘变量和累加变量的标识符。#include void main() int i; /用i作为循环变量 int p=1; /用p作为累乘变量 int s=1; /用s作为累加循环变量 for(i=1;i=10;i+) p*=3; s+=p; printf(%dn,s); 3. 编写一个主函数,已知6a40,15b30,求出满足不定方程2a+5b=120的全部整数组解。如(13,20)就是其中的一组解。#include void main() int a,b; for(a=6;a=40; a+) for(b=15;b=

16、30;b+) if(2*a+5*b=126) printf(%d, %d)n,a,b); 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 the fas celebrations - said he wanted to meet ivory coast international toure

17、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 racism to be dealt with with fines. you can always find money from somebody to p

18、ay 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.this is one of the villains we have today in our game. but it is only with h

19、arsh 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 150th anniversary celebrations and will attend citys premier league match at ch

20、elsea 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 hasopened disciplinary proceedings against cskafor the racist behaviour of their

21、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 complaint. in a statement the russian side added: we found no racist insults from fa

22、ns 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 calm - winds less than 2 mph, with no precipitation or humidity and limited clo

23、ud 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 kilometers), drifting even higher than the cruising altitude of commercial airlin

24、ers (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 slowly step out onto something resembling an olympic

25、 diving platform.below, the earth becomes the concrete bottom of a swimming pool that he wants to land on, but not too hard. still, hell be traveling fast, so despite the distance, it will not be like diving into the deep end of a pool. it will be like he is diving into the shallow end.skydiver preps for the big jumpwhen he jumps, he is expected to reach the speed of sound - 690 mph (1,110 kph) - in less than 40 seconds. like hitting th

温馨提示

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

评论

0/150

提交评论