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

上传人:medalangle361 文档编号:498694 上传时间:2018-11-29 格式:DOC 页数:5 大小:35KB
下载 相关 举报
[计算机类试卷]国家二级C语言机试(操作题)模拟试卷713及答案与解析.doc_第1页
第1页 / 共5页
[计算机类试卷]国家二级C语言机试(操作题)模拟试卷713及答案与解析.doc_第2页
第2页 / 共5页
[计算机类试卷]国家二级C语言机试(操作题)模拟试卷713及答案与解析.doc_第3页
第3页 / 共5页
[计算机类试卷]国家二级C语言机试(操作题)模拟试卷713及答案与解析.doc_第4页
第4页 / 共5页
[计算机类试卷]国家二级C语言机试(操作题)模拟试卷713及答案与解析.doc_第5页
第5页 / 共5页
亲,该文档总共5页,全部预览完了,如果喜欢就下载吧!
资源描述

1、国家二级 C语言机试(操作题)模拟试卷 713及答案与解析 一、程序填空题 1 给定程序中,函数 fun的功能是:计算形参 X所指数组中 N个数的平均值 (规定所有数均为正数 ),作为函数值返回;并将大于平均值的数放在形参 y所指数组中,在主函数中输出。 例如,有 10个正数: 46 30 32 40 6 17 45 15 48 26,平均值为: 30 500000 主函数中输出: 46 32 40 45 48 请在程序的下划线处填入正确的内容并把下划线删除,使程序得出正确的结果。 注意:源 程序存放在考生文件夹下的 BLANK1 C中。不得增行或删行,也不得更改程序的结构 ! 1 #incl

2、ude stdlib h 2 #include stdio h 3 #define N 10 4 double fun(double x, double *y) 5 int i, j; double av; 6 *found* 7 av=_1_; 8 *found* 9 for(i=0; i N; i+) av=av+_2_; 10 for(i=j=0; i N; i+) 11 *found* 12 if(xi av) y_3_=xi; 13 yj=-1; 14 return av; 15 16 main() 17 int i; double xN, yN; 18 fot(i=0; i N;

3、i+)xi=rand() 50; printf( 4 of, xi); 19 printf( n); 20 printf( nThe average is: f n, fun(x, y); 21 for(i=0; yi =O; i+)printf( 5 1f, yi); 22 printf( n); 23 二、程序修改题 2 给定程序 MODI1 C中函数 fun的功能是:根据整型形参 m,计算如下公式的值。 例如,若 m=2000,则应输出: 0 000160。 请改正程序中的语法错误,使它能计算出正确的结果。 注意:不要改动 main函数,不得增行或删行, 也不得更改程序的结构 !1 #i

4、ncludestdio h 2 *found* 3 fun(int m)4 double y=0, d; 5 int i;6 *found* 7 for(i=100, i =m, i+=100)8 d=(double)i*(double)i;9 y+=1 0 d; 10 11 return(y);12 13 main()14 int n=2000; 15 printf( nThe result is 1f n, fun(n); 16 三、程序设计题 3 已知学生的记录由学号和学习成绩构成, N名学生的数据已存入 a结构体数组中。请编写函数 fun,函数的功能是:找出成绩最低的学生记录,通过形参

5、返回主函数 (规定只有一个最低分 )。 注意:部分源程序存在文件 PROG1 C文件中。 请勿改动主函数 main和其他函数中的任何内容,仅在函数 fun的花括号中填入你编写的若干语句。 1 #include stdio h 2 #include string h 3 #define N 10 4 typedef struct ss 5 char num10; int s; STU; 6 void fun(STU a, STU*s) 7 8 9 main() 10 STU aN=A01, 81, A02, 8 9, A03, 66, A0 4, 87,A05, 77, A05, 90, A07

6、, 79, A0 8, 61, A0 9, 80,A10, 71, m; 11 int i; void NONO(); 12 printf(*The original data * n); 13 for(i=0; i N; i+)printf(No= s Nark= d n, ai num, ai s); 14 fun(a, m); 15 printf(*THE RESULT* n); 16 printf(The lowest: s, d n, m num, m s); 17 NONO(); 18 19 void NONO() 20 *本函数用于打开文件,输入数据,调用函数,输出数据,关闭文件

7、。 * 21 FILE *rf, *wf; 22 STU aN, m; 23 int i; 24 rf=fopen(in dat, r); 25 wf=fopen(out dat, w); 26 for(i=0;i 10; i+)fscanf(rf, s d, ai num, 30 fclose(wf); 国家二级 C语言机试(操作题)模拟试卷 713答案与解 析 一、程序填空题 1 【正确答案】 (1)0 (2)xi N (3)j+ 【试题解析】 函数 fun的功能是计算形参 x所指数组中 N个数的平均值,同时利用传址参数传回平均值。 第一空: “return av; ”可知变量 av保存了

8、平均值,故第一空处 av初始化应为 0,即第一空处应填 “0”。 第二空: “for(i=0; i N; i+)av=av+2; ”后面的循环就是比较比平均值大的元素,因此,这个循环结束后 av中的值就是平均值。由 “av=(x0+x1+xN -1)N=x0 N+x1 N+xN -1 N”可知,第二空处应为 “xi N”。 第三空: “if(xi av) y_3_=xi; ”是将 xi保存在 y所指的数组中, i是循环变量, i初始化为 0,故 y的计数变量为 j,故第三空处应为 “j+”。 二、程序修改题 2 【正确答案】 (1)double fun(int m) (2)for(i=100;

9、 i =m; i+=100) 【试题解析】 函数为累计相加,计算公式的值。 (1)第一个标识下的 fun函数的定义,根据题干中给出的公式中的分数部分, 可知应该具有 double类型返回值。所以应将 “fun(int m)”改为 “double fun(int m)”。 (2)第二个标识下的 for循环过程是实现对公式的求解, C语句中 for循环中的多个循环条件表达式是以分号为分隔符,所以第二个标识下 “for(i=100, i =m,i+=100)”改为 “for(i=100; i =m; i+=100)”。 三、程序设计题 3 【正确答案】 1 int i, min=a0 s, j=0; 2 for(i=1; i N; i+) 3 if(min ai s) *如果最低分 min仍大于当前分 * 4 j=i; *记住位置 * 5 min=ai s; *把当前分赋值给 min* 6 7 *s=aj; 【试题解析】 (1)首先指定第一个成绩为最低分数。 (2)再使用一个 for循环把所有的成绩进行比较,找出最低的分数来。

展开阅读全文
相关资源
猜你喜欢
  • BS ISO IEC 26512-2011 Systems and software engineering Requirements for acquirers and suppliers of user documentation《系统和软件工程 用户文件编制的需方和供方的要求》.pdf BS ISO IEC 26512-2011 Systems and software engineering Requirements for acquirers and suppliers of user documentation《系统和软件工程 用户文件编制的需方和供方的要求》.pdf
  • BS ISO IEC 26514-2008 Software and systems engineering - Requirements for designers and developers of user documentation《系统和软件工程 用户文件的设计者和开发者用要求》.pdf BS ISO IEC 26514-2008 Software and systems engineering - Requirements for designers and developers of user documentation《系统和软件工程 用户文件的设计者和开发者用要求》.pdf
  • BS ISO IEC 26515-2012 Systems and software engineering Developing user documentation in an agile environment《软件和软件工程 灵活环境中用户文档的开发》.pdf BS ISO IEC 26515-2012 Systems and software engineering Developing user documentation in an agile environment《软件和软件工程 灵活环境中用户文档的开发》.pdf
  • BS ISO IEC 26550-2015 Software and systems engineering Reference model for product line engineering and management《软件和系统工程 产品线工程参考模型和管理》.pdf BS ISO IEC 26550-2015 Software and systems engineering Reference model for product line engineering and management《软件和系统工程 产品线工程参考模型和管理》.pdf
  • BS ISO IEC 26551-2016 Software and systems engineering Tools and methods for product line requirements engineering《软件和系统工程 生产线需求工程的工具和方法》.pdf BS ISO IEC 26551-2016 Software and systems engineering Tools and methods for product line requirements engineering《软件和系统工程 生产线需求工程的工具和方法》.pdf
  • BS ISO IEC 26555-2015 Software and systems engineering Tools and methods for product line technical management《软件和系统工程 生产线技术管理工具和方法》.pdf BS ISO IEC 26555-2015 Software and systems engineering Tools and methods for product line technical management《软件和系统工程 生产线技术管理工具和方法》.pdf
  • BS ISO IEC 26559-2017 Software and systems engineering Methods and tools for variability traceability in software and systems product line《软件和系统工程 软件和系统产品线中可变性可追溯性的方法和工具》.pdf BS ISO IEC 26559-2017 Software and systems engineering Methods and tools for variability traceability in software and systems product line《软件和系统工程 软件和系统产品线中可变性可追溯性的方法和工具》.pdf
  • BS ISO IEC 27003-2017 Information technology Security techniques Information security management systems Guidance《信息技术 安全技术 信息安全管理系统指南》.pdf BS ISO IEC 27003-2017 Information technology Security techniques Information security management systems Guidance《信息技术 安全技术 信息安全管理系统指南》.pdf
  • BS ISO IEC 27004-2016 Information technology Security techniques Information security management Monitoring measurement analysis and evaluation《信息技术 安全技术 信息安全管理 监测、测量、分析和评.pdf BS ISO IEC 27004-2016 Information technology Security techniques Information security management Monitoring measurement analysis and evaluation《信息技术 安全技术 信息安全管理 监测、测量、分析和评.pdf
  • 相关搜索

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

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