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

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

1、国家二级 C+机试(操作题)模拟试卷 179及答案与解析 一、基本操作题 1 给定程序中,函数 fun的作用是:统计整型变量 m中各数字出现的次数,并存放到数组 a中,其中: a0存放 0出现的次数, a1存放 1出现的次数, a9 存放 9出现的次数。 例如,若 m为 14579233,则输出结果应为: 0, 1, 1, 2, 1, 1, 0, 1, 0, 1, 请在程序的中括号处填入正确的内容并把下划线删除,使程序得出正确的结果。 注意:源程序存放在考生文件夹下的 BLANKI C中。不得增行或删行,也不 得更改程序的结构 ! 试题程序: #include void fun(int m,

2、int a10) int i; for(i=0; i0) *found* i=【 2】; ai+; *found* m=【 3】; main() int m, a10, i; printf(“请输入一个整数: “); SCanf(“ d“, &m); fun(m, a); for(i=0; i #define SIZE 20 fun(double*s, double*w) int k, i; double sum; for(k=2, i=0; i #include #include float fun(float h) void main() FILE*wf; float a; system(

3、“CLS“); printf(“Enter a: “); scanf(“ f“, &a); printf(“The original data is: “); printf(“ f n n“, a); printf(“The result: f n“, fun (a); * wf=fopen(“out dat“, “w“); fprintf(wf, “ f“, fun(8 32533); fclose(wf); * 国家二级 C+机试(操作题)模拟试卷 179答案与解析 一、基本操作题 1 【正确答案】 (1)ai (2)m 10(3)m 10 【试题解析】 数组 a各元素初始化为 0,用求余

4、和整除相结合的方法得到数字的每一位数字,并用它做为数组 a的下标,相应元素加 1。 填空 1:数组 a的 10个元素赋值 为 0。 填空 2: m 10可得到数 m的最后一位数字。 填空 3: m 10可使数字截短,即去掉最后一位。 二、简单应用题 2 【正确答案】 (1)sum=0 0; (2)if(i+1) 5=0) 【试题解析】 (1)变量 sum书写错误。 (2)循环条件 if(i+1 5=0)是一个运算逻辑错误,应先计算 i+1,再对 5求余。 三、综合应用题 3 【正确答案】 float fun(float h) int tnap = (int) (h*1000 +5) 10; *

5、单精度数 h乘以 1000后再加 5,相当于对 h中的第三位小数进行四舍五入,除以 10后将其赋给一个长整型数时就把第三位小数后的数全部截去 * return(fliat)tmp 100 0, *除以 100,保留 2位小数 * 【试题解析】 注意:本题要求对 h的值真正进行四舍五入运算,而不是为了输出,即不能用 printf(“ 7 2f“, h)来直接得到结果。四舍五入算法:如果要求精确到小数点后面的第 n位,则需要对第 n+1位进行运算。方法是将该小数乘以 10的 n+1次方后加 5。然后除以 10并强制转换变量类型为整型,再将该数除以 10的n次方,同时强制转换类型为浮点型。 代码实现如下: int t; *定义整型变量 t* t=(int)(h*10n+1+5) 10; *对 h进行操作,得到值浮点型, t取值时取整数部分。 10n+1为要扩大的倍数 * h=(float)t 10n; *将 t缩小 10n倍,并转换成浮点型 *

展开阅读全文
相关资源
猜你喜欢
  • ASTM A962 A962M-2011 Standard Specification for Common Requirements for Bolting Intended for Use at Any Temperature from Cryogenic to the Creep Range《低温至蠕变范围内任何温度条件下使用的螺栓组件的一般要求的标准.pdf ASTM A962 A962M-2011 Standard Specification for Common Requirements for Bolting Intended for Use at Any Temperature from Cryogenic to the Creep Range《低温至蠕变范围内任何温度条件下使用的螺栓组件的一般要求的标准.pdf
  • ASTM A962 A962M-2011a Standard Specification for Common Requirements for Bolting Intended for Use at Any Temperature from Cryogenic to the Creep Range《用于从低温至蠕变范围内任何温度的螺栓通用要求标准规范》.pdf ASTM A962 A962M-2011a Standard Specification for Common Requirements for Bolting Intended for Use at Any Temperature from Cryogenic to the Creep Range《用于从低温至蠕变范围内任何温度的螺栓通用要求标准规范》.pdf
  • ASTM A962 A962M-2012 Standard Specification for Common Requirements for Bolting Intended for Use at Any Temperature from Cryogenic to the Creep Range《用于从低温至蠕变范围内任何温度的螺栓通用要求标准规格》.pdf ASTM A962 A962M-2012 Standard Specification for Common Requirements for Bolting Intended for Use at Any Temperature from Cryogenic to the Creep Range《用于从低温至蠕变范围内任何温度的螺栓通用要求标准规格》.pdf
  • ASTM A962 A962M-2013 Standard Specification for Common Requirements for Bolting Intended for Use at Any Temperature from Cryogenic to the Creep Range《用于从低温至蠕变范围内任何温度的螺栓通用要求标准规格》.pdf ASTM A962 A962M-2013 Standard Specification for Common Requirements for Bolting Intended for Use at Any Temperature from Cryogenic to the Creep Range《用于从低温至蠕变范围内任何温度的螺栓通用要求标准规格》.pdf
  • ASTM A962 A962M-2013a Standard Specification for Common Requirements for Bolting Intended for Use at Any Temperature from Cryogenic to the Creep Range《用于从低温至蠕变范围内任何温度的螺栓通用要求标准规格》.pdf ASTM A962 A962M-2013a Standard Specification for Common Requirements for Bolting Intended for Use at Any Temperature from Cryogenic to the Creep Range《用于从低温至蠕变范围内任何温度的螺栓通用要求标准规格》.pdf
  • ASTM A962 A962M-2013b Standard Specification for Common Requirements for Bolting Intended for Use at Any Temperature from Cryogenic to the Creep Range《用于从低温至蠕变范围内任何温度的螺栓通用要求标准规格》.pdf ASTM A962 A962M-2013b Standard Specification for Common Requirements for Bolting Intended for Use at Any Temperature from Cryogenic to the Creep Range《用于从低温至蠕变范围内任何温度的螺栓通用要求标准规格》.pdf
  • ASTM A962 A962M-2014 Standard Specification for Common Requirements for Bolting Intended for Use at Any Temperature from Cryogenic to the Creep Range《用于从低温至蠕变范围内任何温度的螺栓通用要求标准规格》.pdf ASTM A962 A962M-2014 Standard Specification for Common Requirements for Bolting Intended for Use at Any Temperature from Cryogenic to the Creep Range《用于从低温至蠕变范围内任何温度的螺栓通用要求标准规格》.pdf
  • ASTM A962 A962M-2014a Standard Specification for Common Requirements for Bolting Intended for Use at Any Temperature from Cryogenic to the Creep Range《用于从低温至蠕变范围内任何温度的螺栓通用要求的标准规格》.pdf ASTM A962 A962M-2014a Standard Specification for Common Requirements for Bolting Intended for Use at Any Temperature from Cryogenic to the Creep Range《用于从低温至蠕变范围内任何温度的螺栓通用要求的标准规格》.pdf
  • ASTM A962 A962M-2015 Standard Specification for Common Requirements for Bolting Intended for Use at Any Temperature from Cryogenic to the Creep Range《用于从低温至蠕变范围内任何温度的螺栓通用要求标准规格》.pdf ASTM A962 A962M-2015 Standard Specification for Common Requirements for Bolting Intended for Use at Any Temperature from Cryogenic to the Creep Range《用于从低温至蠕变范围内任何温度的螺栓通用要求标准规格》.pdf
  • 相关搜索

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

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