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

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

1、国家二级 C语言机试(操作题)模拟试卷 547及答案与解析 一、程序填空题 1 给定程序中,函数 fun的功能是: 将形参 s所指字符串中的数字字符转换成对应的数值,计算出这些数值的累加和作为函数值返回。 例如,形参 s所指的字符串为 abs5defl26jkm8,程序执行后的输出结果为 22。 请在程序的下画线处填入正确的内容并把下画线删除,使程序得出正确的结果。 注意:部分源程序在文件 BLANK1 C中。 不得增行或删行,也不得更改程序的结构 ! 试题程序: #include stdio h #include string h #include ctype h int fun(char*

2、s) int sum=0; while(*s) *found* if(isdigit(*s) sum+=*s 【 1】 ; *found* 【 2】 ; *found* return 【 3】 ; main() char s81; int n; printf(“ nEnter a string: n n“); gets(s); n=fun(s); printf(“ nThe result is: d n n“, n); 二、程序修改题 2 下列给定的程序中,函数 fun的功能是:计算并输出 k以内最大的 10个能被 13或 17整除的自然数之和。 k的值由主函数传入,若 k的值为 500,则函

3、数的值为4622。 请改正程序中的错误,使它能得出正确的结果。 注意:部分源程序在文件 MODll C中,不要改动 main函数,不得增行或删行,也不得更改程序的结构 ! 试题程序: #include stdio h #include conio h #include stdlib h int fun(int k) int m=0, mc=0, j; while(k =2)&(mc 10) *found* if(k 13=0)|(k 17=0) m=m+k; mc+; ) k-; *found* return m; void main() system(“CLS“); printf(“ d n

4、 fun(500); 三、程序设计题 3 编写函数 fun,它的功能是:求小于形参 n同时能被 3与 7整除的所有自然数之和的平方根,并作为函数值返回。 例如,若 n为 1000时,程序输出应为: s=153 909064。 注意:部分源程序在文件 PROGl C中。 请勿改动主函数 main和其他函数中的任何内容,仅在函数 fun的花括号中填入你编写的若干语句。 试题程序: #include math h #include stdio h double fun(int n) main() *主函数 * void NONO(); printf(“s= f n“, fun(1000); NO

5、NO(); void NONO() *本函数用于打开文件,输入数据,调用函数,输出数据,关闭文件。 * FILE*fp, *wf; int i , n; double s; fp=fopen(“in dat“, “r“); wf=fopen(“out dat“, “W“); for(i=0; i 10 ; i+) fscanf(fp, “ d“, &n); s=fun(n); fprintf(wf, “ f n“, s); fclose(fp); fclose(wf); 国家二级 C语言机试(操作题)模拟试卷 547答案与解析 一、程序填空题 1 【正确答案】 (1)48或 0 (2)s+ (

6、3)sum 【试题解析】 本题是把字符串中是数字字符转换成对应的数值并进行累加。 填空 1: 0字符对应的 ASCII码值是 48,因此数字字符转换成对应数值时只要减去 48,即是该数字字符对应的数值,所以应填 48或者 0。 填空 2:判断完一个字符之后,将字符串指针移到下一个位置,所以应填 s+。 填空 3:返回累加和 sum,所以应填 sum。 二、程序修改题 2 【正确答案】 (1)if(k 13=0)|(k 17=0) (2) retum m; 【试题解析】 (1)C语言中, x能被 y整除的表示方法是 x y=0,而不是题目中所表示的 x y=0。所以, if (k 13=0)|(

7、k 17=0)修改后的结果应该是答案所示信息。 (2)程序中缺少程序完整所需的 “,此类信息在做题时一定要注意,可以在做题前先运行一下程序,这样明显的错误一般都会有错误信息显示出来。 比如丢失 “的错误信息是 “Compound Statement missingin Unction fun“。 三、程序设计题 3 【正确答案】 double fun(int n) doubte sum=0 0; int i; for(i=21; i =n; i+) if(i 3=0)&(i 7=0) sum+=i; return sqrt(sum); 【试题解析】 本题考查算术运算的算法,首先利用一个 for循环判断小于 n且能同时被 3和 7整除的整数,并将满足条件的整数累加到 sum,之后调用 sqn函数计算 sum的平方根,并作为函数的返回值。

展开阅读全文
相关资源
猜你喜欢
  • ASTM B622-2017b Standard Specification for Seamless Nickel and Nickel-Cobalt Alloy Pipe and Tube《镍和镍钴合金无缝管和管件的标准规格》.pdf ASTM B622-2017b Standard Specification for Seamless Nickel and Nickel-Cobalt Alloy Pipe and Tube《镍和镍钴合金无缝管和管件的标准规格》.pdf
  • ASTM B624-2007 Standard Specification for High-Strength High-Conductivity Copper-Alloy Wire for Electronic Application《电子用高强度高传导率铜合金线的标准规范》.pdf ASTM B624-2007 Standard Specification for High-Strength High-Conductivity Copper-Alloy Wire for Electronic Application《电子用高强度高传导率铜合金线的标准规范》.pdf
  • ASTM B624-2007(2012) Standard Specification for High-Strength High-Conductivity Copper-Alloy Wire for Electronic Application《电子用高强度高传导率铜合金线的标准规格》.pdf ASTM B624-2007(2012) Standard Specification for High-Strength High-Conductivity Copper-Alloy Wire for Electronic Application《电子用高强度高传导率铜合金线的标准规格》.pdf
  • ASTM B624-2007(2017) Standard Specification for High-Strength High-Conductivity Copper-Alloy Wire for Electronic Application《电子设施用高强度 高导电性铜合金线的标准规格》.pdf ASTM B624-2007(2017) Standard Specification for High-Strength High-Conductivity Copper-Alloy Wire for Electronic Application《电子设施用高强度 高导电性铜合金线的标准规格》.pdf
  • ASTM B625-2005 Standard Specification for UNS N08925 UNS N08031 UNS N08932 UNS N08926 UNS N08354 and UNS R20033 Plate Sheet and Strip《UNS N08925、UNS N08031、NS N08932、UNS N08926、UNS.pdf ASTM B625-2005 Standard Specification for UNS N08925 UNS N08031 UNS N08932 UNS N08926 UNS N08354 and UNS R20033 Plate Sheet and Strip《UNS N08925、UNS N08031、NS N08932、UNS N08926、UNS.pdf
  • ASTM B625-2005(2011) Standard Specification for UNS N08925 UNS N08031 UNS N08932 UNS N08926 UNS N08354 and UNS R20033 Plate Sheet and Strip《UNS N08925 UNS N08031 NS N08932 UNS N089.pdf ASTM B625-2005(2011) Standard Specification for UNS N08925 UNS N08031 UNS N08932 UNS N08926 UNS N08354 and UNS R20033 Plate Sheet and Strip《UNS N08925 UNS N08031 NS N08932 UNS N089.pdf
  • ASTM B625-2014 Standard Specification for UNS N08925 UNS N08031 UNS N08932 UNS N08926 UNS N08354 UNS N08830 and UNS R20033 Plate Sheet and Strip《UNS N08925 UNS N08031 UNS N08932 UN.pdf ASTM B625-2014 Standard Specification for UNS N08925 UNS N08031 UNS N08932 UNS N08926 UNS N08354 UNS N08830 and UNS R20033 Plate Sheet and Strip《UNS N08925 UNS N08031 UNS N08932 UN.pdf
  • ASTM B625-2017 Standard Specification for UNS N08925 UNS N08031 UNS N08034 UNS N08932 UNS N08926 UNS N08354 UNS N08830 and UNS R20033 Plate Sheet and Strip《UNS N08925 UNS N08031 UN.pdf ASTM B625-2017 Standard Specification for UNS N08925 UNS N08031 UNS N08034 UNS N08932 UNS N08926 UNS N08354 UNS N08830 and UNS R20033 Plate Sheet and Strip《UNS N08925 UNS N08031 UN.pdf
  • ASTM B626-2006 Standard Specification for Welded Nickel and Nickel-Cobalt Alloy Tube《焊接镍和镍钴合金管标准规范》.pdf ASTM B626-2006 Standard Specification for Welded Nickel and Nickel-Cobalt Alloy Tube《焊接镍和镍钴合金管标准规范》.pdf
  • 相关搜索

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

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