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

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

1、国家二级 C语言机试(操作题)模拟试卷 553及答案与解析 一、程序填空题 1 函数 fun的功能是:输出 a所指数组中的前 n个数据,要求每行输出 5个数。 请在程序的下画线处填入正确的内容并把下画线删除,使程序得出正确的结果。 注意:源程序存放在考生文件夹下的 BLANK1 C中。不得增行或删行,也不得更改程序的结构 ! 试题程序: #include stdio h #include stcllib h void fun(int *a, int n) int i; for(i=0; i n; i+) *found* if(【 1】 =0) *found* printf(“【 2】 “);

2、*found* printf(“ d“, 【 3】 ); main() int a100=0), i, n; n=22; for(i=0; i n; i+) ai=rand() 21; fun(a, n); printf(“ n“); 二、程序修改题 2 给定程序 MODI1 C中, fun函数的功能是:在任意给定的 N个正整数中,从左到右依次逐个取三个数作为一组,按值大小找出该组数的中值,用该中值替换与该组数对应的原三个数中的中间位置的数。处理后原数列中首尾 2个数不变。处理后数列在主函数中输出。 例如,有 10个正整数如下: 初始数列为: 6 5 7 23 18 5 8 21 45 38

3、第 1组数为: 6 5 7 中值为: 6 替换后的数列为: 6 6 7 23 18 5 8 21 45 38 第 2组数为: 5 7 23 中值为: 7 替换后的数列为: 6 6 7 23 18 5 8 2l 45 38 第 3组数为: 7 23 18 中值为: 18 替换后的数列为: 6 6 7 18 18 5 8 2l 45 38 第 4组数为: 23 18 5中值为: 18 替换后的数列为: 6 6 7 18 18 5 8 21 45 38 第 5组数为: 18 5 8 中值为: 8 替换后的数列为: 6 6 7 18 18 8 8 21 45 38 第 6组数为: 5 8 21 中值为

4、: 8 替换后的数列为: 6 6 7 18 18 8 8 21 45 38 第 7组数为: 8 21 45 中值为: 21 替换后的数列为: 6 6 7 18 18 8 8 21 45 38 第 8组数为: 21 45 38 中值为: 38 替换后的数列为: 6 6 7 18 18 8 8 21 38 38 最终结果为: 6 6 7 18 18 8 8 21 38 38 请改正程序中指定部位的错误,使它能得出正确的结果。 注意:不要改动 main函数,不得增行或删行,也不得更改程序的结构 ! 试题程序: #include Stdio h #define N 10 int findmid(int

5、 a, int b, int c) int t; t=(a b)? (b c?b: (a c?c: a): (a c)?a: (b c)?c: b); *found* return b; void fun(int x) int i, a, b, c, tN; *found* for(i=0; i N; i+)ti=xi for(i=0; i N一 2; i+) a=ti; b=ti+1; c=ti+2; *found* ti+1=findmd(a, b, c); main() int i, xN=6, 5, 7, 23, 18, 5, 8, 21, 45, 38); for(i=0; i N;

6、 i+) printf(“ d“, xi); printf(“ n“); fun(x); for(i=0; i N; i+) printf(“ d“, xi); printf(“ n“); 三、程序设计题 3 请编写函数 fun,函数的功能是查找 x在 s所指数组中下标的位置,并作为函数值返回,若 x不存在,则返回一 1。 注意:部分源程序在文件 PROG1 C文件中,请勿改动主函数 main和其他函数中的任何内容,仅在函数 fun的花括号中填入你编写的若干语句。 试题程序: #include stdio h #include stdlib h #define N 15 void NONO()

7、; int fun(int *s, int x) main() int aN=29, 13, 5, 22, 10, 9, 3, 18, 22, 25, 1 4, 1 5, 2, 7, 27, i, x, index; printf(“a数组中的数据: n“); for(i=0; i N; i+) printf(“ 4d“, ai); printf(“ n“); printf(“给 x输入待查找的数: “); scanf(“ d“, &x); index=fun(a, x); printf(“index= d n“, index); NONO(); void NONO() *本函数用于打开文件,

8、输入数据,调用函数,输出数据,关闭文件。 * FILE*fp, * wf; int i, j, a10, x, index; fp=fopen(”in dat“, “r“); wf=fopen(“out dat“, “w“); for(i=0; i 10; i+) for(j=0; j 1 0; j+) fscanf(fp, “ d“, &aj); fscanf(fp, “ d“, &x); index=fun(a, x); fprintf(wf, “ d n“, index); fclose(fp); fclose(wf); 国家二级 C语言机试(操作题)模拟试卷 553答案与解析 一、程序

9、填空题 1 【正确答案】 (1)i 5 (2) n (3)ai 【试题解析】 填空 1:每行输出 5个数,即当下标值能整除 5时换行。 填空 2:输出换行 符 n。 填空 3:输出数组元素。 二、程序修改题 2 【正确答案】 (1)retum t; (2)for(i 0; i N; i+)ti=xi; (3)xi+1=findmid(a, b, c); 【试题解析】 (1)函数 findmid的功能是找到 a、 b、 c三个数中的中间数,并存放在变量 t中,因此应返回 t。 (2)语法错误,句末缺少分号。 (3)本程序是对数组 x进行操作,数组 t只是用来暂时存放数组 x中的元素,因此此处应为 xi+1 =findmid(a, b, c)。 三、程序设计题 3 【正确答案】 int fun(int*s, int x) int i; for(i=0; i N; i+) if(x=si)return i; return一 1; 【试题解析】 要找出数组中指定数据的下标,首先定义变量 i用于存放数组下标,然后使用循环语句对数组进行遍历,依次取出一个数组元素与指定的数进行比较,若相等,则返回该元素的下标,否则继续判断下一个元素,直到数组结束。若数组结束时仍没有找到与指定数相等的元素,则返回一 1。

展开阅读全文
相关资源
猜你喜欢
  • ASTM B919-2001(2006) Standard Specification for Welded Copper Heat Exchanger Tubes With Internal Enhancement《内部增强的焊接铜热交换器管标准规范》.pdf ASTM B919-2001(2006) Standard Specification for Welded Copper Heat Exchanger Tubes With Internal Enhancement《内部增强的焊接铜热交换器管标准规范》.pdf
  • ASTM B919-2012 Standard Specification for Welded Copper Heat Exchanger Tubes With Internal Enhancement《内部增强的焊接铜热交换器管标准规格》.pdf ASTM B919-2012 Standard Specification for Welded Copper Heat Exchanger Tubes With Internal Enhancement《内部增强的焊接铜热交换器管标准规格》.pdf
  • ASTM B92 B92M-2007 Standard Specification for Unalloyed Magnesium Ingot and Stick For Remelting《回熔用非合金镁锭和镁棒的标准规范》.pdf ASTM B92 B92M-2007 Standard Specification for Unalloyed Magnesium Ingot and Stick For Remelting《回熔用非合金镁锭和镁棒的标准规范》.pdf
  • ASTM B92 B92M-2011 Standard Specification for Unalloyed Magnesium Ingot and Stick For Remelting《回熔用非合金镁锭和镁棒标准规格》.pdf ASTM B92 B92M-2011 Standard Specification for Unalloyed Magnesium Ingot and Stick For Remelting《回熔用非合金镁锭和镁棒标准规格》.pdf
  • ASTM B92 B92M-2017 Standard Specification for Unalloyed Magnesium Ingot and Stick For Remelting《回熔用非合金镁锭和镁棒的标准规格》.pdf ASTM B92 B92M-2017 Standard Specification for Unalloyed Magnesium Ingot and Stick For Remelting《回熔用非合金镁锭和镁棒的标准规格》.pdf
  • ASTM B920-2001(2006)e1 Standard Practice for Porosity in Gold and Palladium Alloy Coatings on Metal Substrates by Vapors of Sodium Hypochlorite Solution《用次氯酸钠液的蒸气测定金属衬底上金和钯合金覆层孔隙度的.pdf ASTM B920-2001(2006)e1 Standard Practice for Porosity in Gold and Palladium Alloy Coatings on Metal Substrates by Vapors of Sodium Hypochlorite Solution《用次氯酸钠液的蒸气测定金属衬底上金和钯合金覆层孔隙度的.pdf
  • ASTM B920-2001(2011) Standard Practice for Porosity in Gold and Palladium Alloy Coatings on Metal Substrates by Vapors of Sodium Hypochlorite Solution《用次氯酸钠溶液蒸汽测定金属基材上的金和钯合金涂层孔隙度的标.pdf ASTM B920-2001(2011) Standard Practice for Porosity in Gold and Palladium Alloy Coatings on Metal Substrates by Vapors of Sodium Hypochlorite Solution《用次氯酸钠溶液蒸汽测定金属基材上的金和钯合金涂层孔隙度的标.pdf
  • ASTM B920-2016 Standard Practice for Porosity in Gold and Palladium Alloy Coatings on Metal Substrates by Vapors of Sodium Hypochlorite Solution《用次氯酸钠液的蒸气测定金属衬底上金和钯合金覆层孔隙度的标准实施规程》.pdf ASTM B920-2016 Standard Practice for Porosity in Gold and Palladium Alloy Coatings on Metal Substrates by Vapors of Sodium Hypochlorite Solution《用次氯酸钠液的蒸气测定金属衬底上金和钯合金覆层孔隙度的标准实施规程》.pdf
  • ASTM B921-2002 Standard Specification for Non-hexavalent Chromium Conversion Coatings on Aluminum and Aluminum Alloys《铝和铝合金上覆盖的非六价铬层的标准规范》.pdf ASTM B921-2002 Standard Specification for Non-hexavalent Chromium Conversion Coatings on Aluminum and Aluminum Alloys《铝和铝合金上覆盖的非六价铬层的标准规范》.pdf
  • 相关搜索

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

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