[计算机类试卷]国家二级C语言机试(操作题)模拟试卷644及答案与解析.doc

上传人:registerpick115 文档编号:498617 上传时间:2018-11-29 格式:DOC 页数:6 大小:29.50KB
下载 相关 举报
[计算机类试卷]国家二级C语言机试(操作题)模拟试卷644及答案与解析.doc_第1页
第1页 / 共6页
[计算机类试卷]国家二级C语言机试(操作题)模拟试卷644及答案与解析.doc_第2页
第2页 / 共6页
[计算机类试卷]国家二级C语言机试(操作题)模拟试卷644及答案与解析.doc_第3页
第3页 / 共6页
[计算机类试卷]国家二级C语言机试(操作题)模拟试卷644及答案与解析.doc_第4页
第4页 / 共6页
[计算机类试卷]国家二级C语言机试(操作题)模拟试卷644及答案与解析.doc_第5页
第5页 / 共6页
点击查看更多>>
资源描述

1、国家二级 C语言机试(操作题)模拟试卷 644及答案与解析 一、程序填空题 1 使用 VC+2010打开考生文件夹下 blank1中的解决方案。此解决方案的项目中包含一个源程序文件 blank1 c。在此程序中,函数 fun的功能是:计算 x所指数组中 N个数的平均值 (规定所有数均为正数 ),平均值通过形参返回给主函数,将小于平均值且最接近平均值的数作为函数值返回,并在主函数中输出。 例如,有 10个正数: 46、 30、 32、 40、 6、 17、 45、 15、 48、 26,平均值为30 500000。 主函数中输出 m=30。 请 在程序的下画线处填入正确的内容并把下画线删除,使程

2、序得出正确的结果。 注意:部分源程序在文件 BLANK1 C中。不得增行或删行,也不得更改程序的结构 ! 试题程序: #include stdlib h #include stdio h #define N10 double fun(double x, double*av) int i, j; double d, s; s=0; for(i=0; i N; i+)s=s+xi; *found* 【 1】 =s N; d=32767; for(i=0; i N; i+) if(xi *av&av-xi =d) *found* d=*av-xi; j=【 2】 ; *found* return【

3、3】 ; main() int i; double xN, av, m; for(i=0; i N; i+) xi=rand() 50; printf(“ 4 0f“, xi); printf(“ n“); m=fun(x, &av); printf(“ nThe aVerage is: f n“, av); printf(“m= 5 1f“, m); printf(“ n“); 二、程序修改题 2 使用 VC+2010打开考生文件夹下 modi1中的解决方案。此解决方案的项目中包含一个源程序文件 modi1 c。在此程序中,函数 fun的功能是:先从键盘上输入一个 3行、 3列的矩阵的各个元

4、素的值,然后输出主对角线元素之和。 请改正程序中的错误,使它能得出正确的结果。 注意:部分源程序在文件 MODI1 C中,不要 改动 main函数,不得增行或删行,也不得更改程序的结构 ! 试题程序: #include stdio h void fun() int a33, sum; int i, j; *found* sum=1; for(i=0; i 3; i+) for(j=0; j 3; j+) *found* scanf(“ d“, aij); for(i=0; i 3; i+) sum=sum+aii; printf(“sum= d n“, sum); void main() fu

5、n(); 三、程序设计题 3 使用 VC+2010打开考生文件夹下 prog1中的解决方案。此解决方案的项目中包含一个源程序文件 prog1 c。在此程序中,请编函数 fun,其功能是将一个数字字符串转换成与其面值相同的长整型整数。可调用 strlen函数求字符串的长度。例如:在键盘输入字符串 2345210,函数返回长整型数 2345210。 注意:部分源程序存在 PROG1 C中,请勿改动主函数 main和其他函数中的任何内容,仅在函数 fun指定的部位填入所编写的若干语句。 试题程序: #include stdio h #include string h void NONO(); lon

6、g fun(char*s) main() char s10; long r; printf(“请输入一个长度不超过 9个字符的数字字符串: “); gets(s); r=fun(s); printf(“r= ld n“, r); NONO(); void NONO() *本函数用于打开文件,输入数据,调用函数,输出数据,关闭文件。 * FILE*fp, *wf; int i; long r; char s10, *p; fp=fopen(“in dat“, “r“); wf=fopen(“out dat“, “w“); for(i=0; i 10; i+) fgets(s, 10, fp);

7、P=strchr(s, n); if(p)*p=0; r=fun(s); fprintf(wf, “ ld n“, r); fclose(fp); fclose(wf); 国家二级 C语言机试(操作题)模拟试卷 644答案与解析 一、程序填空题 1 【正确答案】 (1)*av (2)i (3)xj 【试题解析】 填空 1:从原程序中可以看出 *av代表的是平均值,而 s N表示的就是平均值,因此本空应该填 *av。 填空 2: if语句来判断找最接近平均值的数,因而此空应该填 i。 填空 3:题目要求将小于平均值且最接近平均值的数作为函数返回,而 j表达的是最接近平均值的数在数组中的下标,因而

8、本空应该填写 xj。 二、程序修改题 2 【正确答案】 (1)sum=0; (2)scanf(“ dt“, &aij); 【试题解析】 该题考查对循环语句的掌握和对数组概念的理解。本题的解题思路为:先从键盘输入一个 33矩阵,然后循环累加,执行循环语句中的sum=sum+aii;。因为变量 sum用来存放累加后的结果,所以应对其初始化为0。第二处错误考查标准输入函数 scanf的格式,被赋值的变量前要加上取地址符“&“。 三、程序设计题 3 【正确答案】 long fun(char*s) int i, len; long sum=0; len=strlen(s); for(i=0; i len; i+) sum=sum*10+*s-0; s+; return sum; 【试题解析】 要把一个数字字符转为相应的数字,只要用它的 ASCII码减去 48即可。要把数字字符串转为相应的数字,则要从左到右依次取出字符转为相应数字,乘 10再加上下一位数字。

展开阅读全文
相关资源
猜你喜欢
  • BS PD IEC TS 62763-2013_5284 Pilot function through a control pilot circuit using PWM (pulse width modulation) and a control pilot wire《通过控制导向线使用PWM (脉冲宽度调制) 的导向功能和控制导向线》.pdf BS PD IEC TS 62763-2013_5284 Pilot function through a control pilot circuit using PWM (pulse width modulation) and a control pilot wire《通过控制导向线使用PWM (脉冲宽度调制) 的导向功能和控制导向线》.pdf
  • BS ISO 8070-2007 Milk and milk products - Determination of calcium sodium potassium and magnesium contents - Atomic absorption spectrometric method《牛奶和奶制品 钙、钠、钾和镁含量的测定 原子吸.pdf BS ISO 8070-2007 Milk and milk products - Determination of calcium sodium potassium and magnesium contents - Atomic absorption spectrometric method《牛奶和奶制品 钙、钠、钾和镁含量的测定 原子吸.pdf
  • BS ISO 8082-1-2009 Self-propelled machinery for forestry - Laboratory tests and performance requirements for roll-over protective structures - General machines《林业用自推进机械 防倾.pdf BS ISO 8082-1-2009 Self-propelled machinery for forestry - Laboratory tests and performance requirements for roll-over protective structures - General machines《林业用自推进机械 防倾.pdf
  • BS ISO 8082-2-2011 Self-propelled machinery for forestry Laboratory tests and performance requirements for roll-over protective structures Machines having a rotating platf.pdf BS ISO 8082-2-2011 Self-propelled machinery for forestry Laboratory tests and performance requirements for roll-over protective structures Machines having a rotating platf.pdf
  • BS ISO 8083-2006 Machinery for forestry - Falling-object protective structures (FOPS) - Laboratory tests and performance requirements《林业机械 落体防护装置(FOPS) 实验室试验和性能要求》.pdf BS ISO 8083-2006 Machinery for forestry - Falling-object protective structures (FOPS) - Laboratory tests and performance requirements《林业机械 落体防护装置(FOPS) 实验室试验和性能要求》.pdf
  • BS ISO 8086-2004 Dairy plant - Hygiene conditions - General guidance on inspection and sampling procedures《乳品厂 卫生条件 检验和取样程序通用指南》.pdf BS ISO 8086-2004 Dairy plant - Hygiene conditions - General guidance on inspection and sampling procedures《乳品厂 卫生条件 检验和取样程序通用指南》.pdf
  • BS ISO 8096-2005 Rubber- or plastics-coated fabrics for water resistant clothing - Specification《雨衣用橡胶或塑料涂覆织物 规范》.pdf BS ISO 8096-2005 Rubber- or plastics-coated fabrics for water resistant clothing - Specification《雨衣用橡胶或塑料涂覆织物 规范》.pdf
  • BS ISO 8097-2001 Aircraft Minimum airworthiness requirements and test conditions for certified air cargo unit load devices《航空器 经认证的航空货运集装单元装置最低适航性要求和试验条件》.pdf BS ISO 8097-2001 Aircraft Minimum airworthiness requirements and test conditions for certified air cargo unit load devices《航空器 经认证的航空货运集装单元装置最低适航性要求和试验条件》.pdf
  • BS ISO 8114-1993 Textile machinery and accessories - Spindles for ring-spinning and doubling machines - List of equivalent terms《纺织机械和附件 环锭纺纱机和并线机用锭子 同义术语表》.pdf BS ISO 8114-1993 Textile machinery and accessories - Spindles for ring-spinning and doubling machines - List of equivalent terms《纺织机械和附件 环锭纺纱机和并线机用锭子 同义术语表》.pdf
  • 相关搜索

    当前位置:首页 > 考试资料 > 职业资格

    copyright@ 2008-2019 麦多课文库(www.mydoc123.com)网站版权所有
    备案/许可证编号:苏ICP备17064731号-1