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

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

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

2、n(char*s) 5 int sum=0; 6 while(*s) 7 *found* 8 if(isdigit(*s) 9 sum+=* s-【 1】 ; 10 * found* 11 【 2】 ; 12 13 *found* 14 return【 3】 ; 15 16 main() 17 char s81; int n; 18 printf( nEnter a string: n n); 19 gets(s); 20 n=fun(s); 21 printf( nThe result is: d n n, n); 22 二、程序修改题 2 下列给定程序中,函数 fun和 funx的功能是:

3、用二分法求方程 2x3-4x2+3x-6=0的一个 根,并要求绝对误差不超过 0 001。 例如,若给 m输入 -100,给 n输入 90,则函数求得的一个根为 2 000。 请改正程序中的错误,使它能得出正确的结果。 注意:不要改动 main函数,不得增行或删行,也不得更改程序的结构 ! 试题程序: 1 #include stdio h 2 #include math h 3 double funx(double x) 4 5 return (2*x*x*x-4*x*x+3*x-6); 6 7 double fun(double m, double n) 8 9 *found* 10 int

4、 r; 11 r=(m+n) 2; 12 *found* 13 while(fabs(n-m) 三、程序设计题 3 函数 fun的功能是:将 a、 b中的两个正整数合并形成一个新的整数放在 c中。合并的方式是:将 a中的十位和个位数依次放在变量 e的十位和千位上, b中的十位和个位数依次放在变量 c的个位和百位上。 例如,当 a=45, b=12。调用该函数后, c=5241。 注意:部分源程序在文件 PROG1 C中。 请勿改动 main函数和其他函数中的任何内容,仅在函数 fun的花括号中填入你编写的若干语句。 试题程序: 1 #include stdio h 2 void fun(int

5、 a, int b, long*c) 3 4 5 6 main() 7 int a, b; long c; void NONO(); 8 printf(Input a, b: ); 9 scanf( d d, a, b); 10 fun(a, b, c); 11 printf(The result is: ld n, c); 12 NONO(); 13 14 void NONO() 15 *本函数用于打开文件,输入数据,调用函数,输出数据,关闭文件。 * 16 FILE * rf, *wf ; 17 int i, a, b; long c; 18 rf=fopen(in dat, r); 19

6、 wf=fopen(out dat, w); 20 for(i=0; i0 001) 【试题解析】 (1)程序中会发现 r=(m+n) 2,而 m和 n都是 double型的,并且根据题意可知,变量 r需要定义为 double型。 (2)绝对误差不超过 0 001,所以循环条件应为 fabs(n-m)0 001。 三、程序设计题 3 【正确答案】 1 void fun(int a, int b, long*c) 2 3 *c=(a 10)*1000+(b 10)*100+(a 10)*10+(b 10); 4 【试题解析】 本题是给出两个两位数的正整数分别取出各位上的数字,再按条件组成一个新数。取 a十位数字的方法 a 10,取 a个位数字的方法 a 10。同理可取出整数 b的个位数和十 位数。

展开阅读全文
相关资源
猜你喜欢
  • BS ISO 614-2012 en_8589  Ships and marine technology Toughened safety glass panes for rectangular windows and side scuttles Punch method of non-destructive strength testing《船舶和海洋技术 舷.pdf BS ISO 614-2012 en_8589 Ships and marine technology Toughened safety glass panes for rectangular windows and side scuttles Punch method of non-destructive strength testing《船舶和海洋技术 舷.pdf
  • BS ISO 6162-1-2012 en_5574  Hydraulic fluid power Flange connections with split or one-piece flange clamps and metric or inch screws Flange connectors ports and mounting surfaces .pdf BS ISO 6162-1-2012 en_5574 Hydraulic fluid power Flange connections with split or one-piece flange clamps and metric or inch screws Flange connectors ports and mounting surfaces .pdf
  • BS ISO 6358-1-2013 en_9874  Pneumatic fluid power Determination of flow-rate characteristics of components using compressible fluids General rules and test methods for steady-state flow《气压.pdf BS ISO 6358-1-2013 en_9874 Pneumatic fluid power Determination of flow-rate characteristics of components using compressible fluids General rules and test methods for steady-state flow《气压.pdf
  • BS ISO 6362-6-2012 en_2338  Wrought aluminium and aluminium alloys Extruded rods bars tubes and profiles Round square rectangular and hexagonal tubes Tolerances on shape and dimensions《锻造铝和.pdf BS ISO 6362-6-2012 en_2338 Wrought aluminium and aluminium alloys Extruded rods bars tubes and profiles Round square rectangular and hexagonal tubes Tolerances on shape and dimensions《锻造铝和.pdf
  • BS ISO 639-4-2010 en_1543  Codes for the representation of names of languages - General principles of coding of the representation of names of languages and related entities and application guidel.pdf BS ISO 639-4-2010 en_1543 Codes for the representation of names of languages - General principles of coding of the representation of names of languages and related entities and application guidel.pdf
  • BS ISO 6432-2015 en_3486  Pneumatic fluid power Single rod cylinders 1 000 kPa (10 bar) series bores from 8 mm to 25 mm Basic and mounting dimensions《气动流体动力.单杆汽缸.1100kPa(10bar)系列..pdf BS ISO 6432-2015 en_3486 Pneumatic fluid power Single rod cylinders 1 000 kPa (10 bar) series bores from 8 mm to 25 mm Basic and mounting dimensions《气动流体动力.单杆汽缸.1100kPa(10bar)系列..pdf
  • BS ISO 6953-2-2015 en_6113  Pneumatic fluid power Compressed air pressure regulators and filter-regulators Test methods to determine the main characteristics to be included in literature from supp.pdf BS ISO 6953-2-2015 en_6113 Pneumatic fluid power Compressed air pressure regulators and filter-regulators Test methods to determine the main characteristics to be included in literature from supp.pdf
  • BS ISO 6953-3-2013 en_2478  Pneumatic fluid power Compressed air pressure regulators and filter-regulators Alternative test methods for measuring the flow-rate characteristics of pressure regulat.pdf BS ISO 6953-3-2013 en_2478 Pneumatic fluid power Compressed air pressure regulators and filter-regulators Alternative test methods for measuring the flow-rate characteristics of pressure regulat.pdf
  • BS ISO 6980-2-2004 en_5317  Nuclear energy - Reference beta-particle radiation - Calibration fundamentals related to basic quantities characterizing the radiation field《核能.参考β粒子辐.pdf BS ISO 6980-2-2004 en_5317 Nuclear energy - Reference beta-particle radiation - Calibration fundamentals related to basic quantities characterizing the radiation field《核能.参考β粒子辐.pdf
  • 相关搜索

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

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