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

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

1、国家二级 C语言机试(操作题)模拟试卷 426及答案与解析 一、程序填空题 1 给定程序中,函数 fun的功能是:将 a所指 43矩阵中第 k行的元素与第 0行元素交换。 例如,有下列矩阵: 1 2 3 4 5 6 7 8 9 10 11 12 若 k为 2,程序执行结果为: 7 8 9 4 5 6 1 2 3 10 11 12 请在程序的下画线处 填入正确的内容并把下画线删除,使程序得出正确的结果。 注意:部分源程序在文件 BLANK1 C中。 不得增行或删行,也不得更改程序的结构 ! 试题程序: #include stdio h #define N 3 #define M 4 /*foun

2、d*/ void fun(int(* a)N, int 【 1】 ) int i, temp; /*found*/ for(i=0 j i 【 2】 ; i+) temp=a0i; /*found*/ a0i=【 3】 ; aki=temp; main() int xMN=1, 2, 3), 4, 5, 6), 7, 8, 9), 1 0, 11, 12), i, j; printf(“The array before mov一 ing: nn“); for(i=0; i M; i+) for(j=0; j N; j+) printf(“ 3d“, xij); printf(“nn“); fu

3、n(x, 2); printf(“The array after moving: nn“); for(i=0; i M; i+) for(j=0; j N; J+) printf(“ 3d“, xij); printf(“nn“); 二、程序修改题 2 下列给定程序中,函数 fun的功能是:读入一个字符串 (长度 20),将该字符串中的所有字符按 ASCII码值升序排序后输出。例如,若输入 “edcba“,则应输出“abcde“。 请改正程序中的错误,使它能得出正确的结果。 注意:部分源程序在文件 MOD11 C中,不要改动 main函数,不得增行或删行,也不得更改程序的结构! 试题程序: #

4、include string*h #include stdio*h void fun (char t ) char c; int i, j ; /*found*/ for (i = str1en (t) ; i; i 一一 ) for(j=0; j i; j+) /*found*/ if(tj tj+1) c=tj; tj=tj+1; tj+1=c; main() char S81; printf(“nPlease enter a character string: “); gets(s); printf (“nnBefore sorting: n s“, s); fun(s); printf

5、nAfter sorting decendingly: n s“, s); 三、程序设计题 3 请编写一个函数 fun,它的功能是:将 ss所指字符串中所有下标为奇数位置的字母转换为大写 (若该位置上不是字母,则不转换 )。 例如,若输入 “abc4Efg“,则应输出 “aBc4EFg“。 注意:部分源程序在文件 PROG1 C中。 请勿改动主函数 main和其他函数中的任何内容,仅在函数 fun的花括号中填入你编写的若干语句。 试题程序: #include conio h #include stdio h #include string h #include stdlib h void

6、fun(char*ss) void main() FILE*wf; char tt81, s81=“abc4Efg“; system(“CLS“); printf(“nPlease enter an string within 80 characters: n“); gets(tt); printf(“nnAfter changing, the stringn s“, tt); fun(tt); printf(“nbecomesn sn“, tt); /*/ wf=fopen(“out dat“, “W“); fun(s); fprintf(wf, “ s“, s); fclose(wf);

7、/*/ 国家二级 C语言机试(操作题)模拟试卷 426答案与解析 一、程序填空题 1 【正确答案】 (1)k (2)N (3)aki 【试题解析】 填空 1:变量 k在函数体 fun中已经使用,但在函数体中没有定义,肯定是在函数的形参中定义的,所以应填 k。 填空 2:数组共 N列,所以应填 N。 填空 3:这部分语句实现的功能是变量值的交换,所以应填 aki。 二、程序修改题 2 【正确答案】 (1)for(i=str1en(t) 一 1; i; l一一)或 for(i=str1en(t)一 1; i 0; 1一一 ) (2)if(tj tj+1) 【试题解析】 (1)本题是利用选择法对数组

8、元素进行 比较排序。所谓选择法,是依次用当前取得的元素和其后面的元素进行比较,在第一个元素和其后面的元素顺次比较时,可以借助中间变量来对两个数进行交换,要保证第一个元素始终存放数组中的最大数,以后依次挑选出次大数,这样最终的数组就是有序的。 str1en函数所求得的字符串长度,数组最大下标表示为字符串长度减 1,所以要减 1。 (2)这里是一个分析逻辑错误,题中要求按升序排序,所以应改为 if (tj tj+1)。 三、程序设计题 3 【正确答案】 void fun (char *ss) int i; for(i=; ssi!=0; i+) /*将 ss所指字符串中所有下标为奇数 位置的字母转换为大写 */ if(i 2=1&ssi =a&ssi =z) ssi=ssi一 32; 【试题解析】 该题要求将给定字符串中奇数位置的字母转换为大写,需要先判断奇数位置以及是否是小写字母,如果是再通过其转换方法进行转换。从 C语言的学习中知道,只要将小写字母减去 32即转成大写字母,将大写字母加上 32即转成小写字母。本程序用 if语句实现转换功能。

展开阅读全文
相关资源
猜你喜欢
  • BS PD IEC TS 62763-2013_5284 Pilot function through a control pilot circuit using PWM (pulse width modulation) and a control pilot wire《通过控制导向线使用PWM (脉冲宽度调制) 的导向功能和控制导向线》.pdf BS PD IEC TS 62763-2013_5284 Pilot function through a control pilot circuit using PWM (pulse width modulation) and a control pilot wire《通过控制导向线使用PWM (脉冲宽度调制) 的导向功能和控制导向线》.pdf
  • BS ISO 8070-2007 Milk and milk products - Determination of calcium sodium potassium and magnesium contents - Atomic absorption spectrometric method《牛奶和奶制品 钙、钠、钾和镁含量的测定 原子吸.pdf BS ISO 8070-2007 Milk and milk products - Determination of calcium sodium potassium and magnesium contents - Atomic absorption spectrometric method《牛奶和奶制品 钙、钠、钾和镁含量的测定 原子吸.pdf
  • BS ISO 8082-1-2009 Self-propelled machinery for forestry - Laboratory tests and performance requirements for roll-over protective structures - General machines《林业用自推进机械 防倾.pdf BS ISO 8082-1-2009 Self-propelled machinery for forestry - Laboratory tests and performance requirements for roll-over protective structures - General machines《林业用自推进机械 防倾.pdf
  • BS ISO 8082-2-2011 Self-propelled machinery for forestry Laboratory tests and performance requirements for roll-over protective structures Machines having a rotating platf.pdf BS ISO 8082-2-2011 Self-propelled machinery for forestry Laboratory tests and performance requirements for roll-over protective structures Machines having a rotating platf.pdf
  • BS ISO 8083-2006 Machinery for forestry - Falling-object protective structures (FOPS) - Laboratory tests and performance requirements《林业机械 落体防护装置(FOPS) 实验室试验和性能要求》.pdf BS ISO 8083-2006 Machinery for forestry - Falling-object protective structures (FOPS) - Laboratory tests and performance requirements《林业机械 落体防护装置(FOPS) 实验室试验和性能要求》.pdf
  • BS ISO 8086-2004 Dairy plant - Hygiene conditions - General guidance on inspection and sampling procedures《乳品厂 卫生条件 检验和取样程序通用指南》.pdf BS ISO 8086-2004 Dairy plant - Hygiene conditions - General guidance on inspection and sampling procedures《乳品厂 卫生条件 检验和取样程序通用指南》.pdf
  • BS ISO 8096-2005 Rubber- or plastics-coated fabrics for water resistant clothing - Specification《雨衣用橡胶或塑料涂覆织物 规范》.pdf BS ISO 8096-2005 Rubber- or plastics-coated fabrics for water resistant clothing - Specification《雨衣用橡胶或塑料涂覆织物 规范》.pdf
  • BS ISO 8097-2001 Aircraft Minimum airworthiness requirements and test conditions for certified air cargo unit load devices《航空器 经认证的航空货运集装单元装置最低适航性要求和试验条件》.pdf BS ISO 8097-2001 Aircraft Minimum airworthiness requirements and test conditions for certified air cargo unit load devices《航空器 经认证的航空货运集装单元装置最低适航性要求和试验条件》.pdf
  • BS ISO 8114-1993 Textile machinery and accessories - Spindles for ring-spinning and doubling machines - List of equivalent terms《纺织机械和附件 环锭纺纱机和并线机用锭子 同义术语表》.pdf BS ISO 8114-1993 Textile machinery and accessories - Spindles for ring-spinning and doubling machines - List of equivalent terms《纺织机械和附件 环锭纺纱机和并线机用锭子 同义术语表》.pdf
  • 相关搜索

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

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