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

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

1、国家二级 C语言机试(操作题)模拟试卷 585及答案与解析 一、程序填空题 1 给定程序中,函数 fun的功能是: 将形参指针所指结构体数组中的三个元素按 num成 员进行升序排列。 请在程序的下画线处填入正确的内容并把下画线删除,使程序得出正确的结果。 注意:部分源程序给出如下。 不得增行或删行,也不得更改程序的结构 ! 试题程序: #include stdio h typedef struct int num; char name10; PERSON; *found* void fun(PERSON【 1】 *found* 【 2】 temp; if(std0 num std1 num)

2、temp=std0; std0=std1; std1=temp; if(stall0 num stdE2 hum) toxnp=stdl0; stdE0=std2; std2=temp; if(stalll rlLlm stall2 num) temp=std1; std1=std2; std2=temp; main() PERSON std=(5, “7, hanghu”, 2, “WangLi”, 6, “LinMin”); int i; *found* fun【 3】 ; printf(“The result i s”: ); for(i=0; i 3; i+) printf(“ d,

3、s”, stdi num, stdi name); 二、程序修改题 2 下列给定程序中函数 fun的功能是:将 m(1m10)个字符串连接起来,组成一个新串,放入 pt所指存储区中。例如:把三个串 “abe”、 “CD”、 “EF”连接起来,结果是 “abeCDEF”。 请改正程序中的错误,使它能得出正确的结果。 注意:不要改动 main函数,不得增行或删行,也不得更改程序的结构 ! 试题程序: #include stdio h #include string h void fun(char sir10, int m, char*pt) *found* Int k, q, i; for(k=0

4、; k m; k+) q=strlen(strk); for(i=0; i q; i+) *found* pti=strk, i; pt+=q; pt0=0; main() int m, h; char s1010, p120; printf(“Please enter m: ”); scanf(“ d”, &m); gets(s0); printf(“Please enter d string”, m); for(h=0; h m; h+) gets(sh); fun(s, m, p); printf(“The result is: s”, p); 三、程序设计题 3 下列程序定义了 NN的

5、二维数组,并在主函数中自动赋值。请编写函数 fun(im a N),该函数的功能是:将数组左下半三角元素中的值全部置成 0。 例如 a数组中的值为: 1 9 7 2 3 8 4 5 6 则返回主程序后 a数组中的值应为: 0 9 7 0 0 8 0 0 0 注意:部分源程序给出如下。 请勿改动 main函数和其他函数中的任何内容,仅在函数 fun的花括号中填入你编写的若干语句。 试题程序: #include conio h #include stdio h #include Stdlib h #define N 5 void fun(int aN) void main() int aNN, i

6、, j; system(“CLS“); printf(“*The array*n“); for(i=0; i N; i+) *产生一个随机的 5*5矩阵 * for(j=0; j N; j+) aij=rand() 10; printf(“ 4“, aij); printf(“ n“); fun(a); printf(“THE RESULT n“); for(i=0; i N; i+) for(j=0; j N; j+) printf(“ 4d“, aij); printf(“ n“); 国家二级 C语言机试(操作题)模拟试卷 585答案与解析 一、程序填空题 1 【正确答案】 (1)std

7、(2)PERSON (3)std 【试题解析】 本题考查:数据类型的定义;数组元素的操作; 函数参数的传递。 要使用函数对整个数组进行操作时,应使用数组名作为函数的实参。当使用数组名作实参时,函数传递的实际上是数组的首地址,而并非数组本身,此时形参除了可以定义为指针变量外,还可以定义为数组,并且数组可以不指定大小,但无论用哪种形式,程序在编译时都将其作为一个指针变量处理。 填空 1:定义形参变量引用数组 std,此时形参可以定义为指针变量,也可以定义为数组。由下文可知,程序是通过数组下标对数组元素进行操作的,因此形参应使用数组形式,而非指针形式。 填空 2:程序使用变量 temp交换结构体数组

8、元素的值,因 而 temp应定义为PERSON型。 填空 3:程序通过函数 fun对数组 std进行操作,因此函数的实参应为 std。 二、程序修改题 2 【正确答案】 (1)int k, q, i; (2)pti=strki; 【试题解析】 本题考查: C语言的书写和语法性错误,这类错误比较简单,只要编译程序,根据错误提示修改即可。 (1)关键字书写错误,定义整型变量的关键字应使用 int,而非 Int。 (2)数组元素表示错误,表示二维数组元素,应使用方括号将行坐标和列坐标分别括起来,即 strk, i应改为: strki。 三、程序设计题 3 【正确答案】 void fun(int aN) int i, j; for(i=0; i N; i+) for(j: 0 ; j =i; j+) aij=0; *将数组左下半三角元素中的值全部置成 0* 【试题解析】 本题考查: for循环语句,使用嵌套循环语句遍历二维数组的各个元素;二维数组元素的引用。 对于 NN二维数组,如何表示其左下半三角元素,可以通过以下语句实现。 for(i=0; i n; i+) for(j=0; j =i; j+) 外层循环用来控制矩阵的行下标,内层循环控制矩阵的列下标。注意列下标的取值范围,因为要表示下三角元素,所以 j的范围是 0 i。

展开阅读全文
相关资源
猜你喜欢
  • ASTM C1572-2010 Standard Guide for Dry Lead Glass and Oil-Filled Lead Glass Radiation Shielding Window Components for Remotely Operated Facilities《远程操作设备的干铅玻璃和充油铅玻璃辐射屏蔽窗设备标准指南》.pdf ASTM C1572-2010 Standard Guide for Dry Lead Glass and Oil-Filled Lead Glass Radiation Shielding Window Components for Remotely Operated Facilities《远程操作设备的干铅玻璃和充油铅玻璃辐射屏蔽窗设备标准指南》.pdf
  • ASTM C1574-2004 Standard Guide for Determining Blown Density of Pneumatically Applied Loose-Fill Mineral Fiber Thermal Insulation《喷射松填充矿物纤维热绝缘材料膨胀密度测定的标准指南》.pdf ASTM C1574-2004 Standard Guide for Determining Blown Density of Pneumatically Applied Loose-Fill Mineral Fiber Thermal Insulation《喷射松填充矿物纤维热绝缘材料膨胀密度测定的标准指南》.pdf
  • ASTM C1574-2004(2008) Standard Guide for Determining Blown Density of Pneumatically Applied Loose-Fill Mineral Fiber Thermal Insulation.pdf ASTM C1574-2004(2008) Standard Guide for Determining Blown Density of Pneumatically Applied Loose-Fill Mineral Fiber Thermal Insulation.pdf
  • ASTM C1574-2004(2008)e1 Standard Guide for Determining Blown Density of Pneumatically Applied Loose-Fill Mineral Fiber Thermal Insulation《喷射松填充矿物纤维热绝缘材料膨胀密度测定的标准指南》.pdf ASTM C1574-2004(2008)e1 Standard Guide for Determining Blown Density of Pneumatically Applied Loose-Fill Mineral Fiber Thermal Insulation《喷射松填充矿物纤维热绝缘材料膨胀密度测定的标准指南》.pdf
  • ASTM C1574-2004(2013) Standard Guide for Determining Blown Density of Pneumatically Applied Loose-Fill Mineral Fiber Thermal Insulation《喷射松填充矿物纤维热绝缘材料膨胀密度测定的标准指南》.pdf ASTM C1574-2004(2013) Standard Guide for Determining Blown Density of Pneumatically Applied Loose-Fill Mineral Fiber Thermal Insulation《喷射松填充矿物纤维热绝缘材料膨胀密度测定的标准指南》.pdf
  • ASTM C1576-2005 Standard Test Method for Determination of Slow Crack Growth Parameters of Advanced Ceramics by Constant Stress Flexural Testing (Stress Rupture) at Ambient Temperat.pdf ASTM C1576-2005 Standard Test Method for Determination of Slow Crack Growth Parameters of Advanced Ceramics by Constant Stress Flexural Testing (Stress Rupture) at Ambient Temperat.pdf
  • ASTM C1576-2005(2010) Standard Test Method for Determination of Slow Crack Growth Parameters of Advanced Ceramics by Constant Stress Flexural Testing (Stress Rupture) at Ambient Te.pdf ASTM C1576-2005(2010) Standard Test Method for Determination of Slow Crack Growth Parameters of Advanced Ceramics by Constant Stress Flexural Testing (Stress Rupture) at Ambient Te.pdf
  • ASTM C1576-2005(2017) Standard Test Method for Determination of Slow Crack Growth Parameters of Advanced Ceramics by Constant Stress Flexural Testing (Stress Rupture) at Ambient Te.pdf ASTM C1576-2005(2017) Standard Test Method for Determination of Slow Crack Growth Parameters of Advanced Ceramics by Constant Stress Flexural Testing (Stress Rupture) at Ambient Te.pdf
  • ASTM C1577-2007a Standard Specification for Precast Reinforced Concrete Monolithic Box Sections for Culverts Storm Drains and Sewers Designed According to AASHTO LRFD《根据AASHTO LRFD.pdf ASTM C1577-2007a Standard Specification for Precast Reinforced Concrete Monolithic Box Sections for Culverts Storm Drains and Sewers Designed According to AASHTO LRFD《根据AASHTO LRFD.pdf
  • 相关搜索

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

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