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

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

1、国家二级 C语言机试(操作题)模拟试卷 107及答案与解析 一、程序填空题 1 下列给定程序中,函数 fun的功能是:将 NN矩阵中元素的值按列向右移动 1个位置,右边被移出矩阵的元素绕回左边第 1列。 例如, N=3,有下列矩阵 1 2 3 4 5 6 7 8 9 计算结果为: 3 1 2 6 4 5 9 7 8 请在程序的下画线处填入正确的内容并将下画线删除,使程序得出正确的结果 。 注意:部分源程序给出如下。 不得增行或删行,也不得更改程序的结构 ! 试题程序: #include stdio h #define N 4 void fun(int(*t)N) int i, j, x; fo

2、r(i=0; i 【 1】 , i+) x=ti【 2】 , for(j=N一 1; j 0, j一一 ) tij=tij1; ti【 3】 =x; main() int i, j, tN=21, 12, 13, 24, 25, 16, 47, 38, 29, 11, 32, 54, 42, 21, 33, 10; printf(“The orriginal array: n”); for(i=0; i N; i+) for(j=0;j N; j+) printf(“ 2d”, tij), printf(“ n”), fun(t); printf(“ nThe result is: n”);

3、for(i=0; i N; i+) for(j=0; j N; j+) printf(“ 2d”, tij); printf(“ n”); 二、程序修改题 2 下列程序中,函数 fun的功能是:按顺序给 s所指数组中的元素赋予从 2开始的偶数,然后再按顺序对每 5个元素求一个平均值,并将这些值依次存放在 W所指的数组中。若 s所指数组中元素的个数不是 5的倍数,则多余部分忽略不计。 例如, s所指数组有 14个元素,则只对前 10个元素进行处理 ,不对最后的 4个元素求平均值。 请改正程序中的错误,使它能得出正确的结果。 注意:不要改动 main函数,不得增行或删行,也不得更改程序的结构 !

4、试题程序: #include stdio h #define SIZE 20 fun(double*s, double*w) *nt k, i; double sum; for(k=2, i=0, i SIZE; i+) ( si=k; k+=2; ) /*found*/ sun=0 0; for(k=0, i=0, i SIZE; i+) sum+=si; /*found*/ if(i+1 5=0) wk=sum 5; sum=0; k+, ) return k; main() double aSIZE,bSIZE 5; int i, k, k=fun(a, b); printf(“The

5、original data: n”); for(i=0, i SIZE; i+) if(i 5=0)printf(“ n”); printf(“ 4 0f”, ai); printf(“ n nThe result: n”); for(i=0; i k, i+) printf(“ 6 2f”, bi); printf(“ n、 n”); 三、程序设计题 3 编写函数 fun,其功能是:将 ss所指字符串中所有下标为奇数位上的字母转换为大写 (若该位置上不是字母,则不转换 )。 例如,若输入 “abc4EFg”,则应输出 “aBc4EFg”。 注意:部分源程序给出如下。 请勿改动主函数 main

6、和其他函数中的任何内容,仅在函数 fun的花括号中填入你编写的若干语句。 试题程序: #include conio h #include stdio h #include string h void fun(char*ss) void main(void) char tt51; printf(“ nPlease enter an character string within 50 characters: n”); gets(tt); printf(“ n nAfter changing, the string n S”, tt), fun(tt); printf(“ nbecomes n S

7、 tt); 国家二级 C语言机试(操作题)模拟试卷 107答案与解析 一、程序填空题 1 【正确答案】 (1)N (2)N1 (3)0 【试题解析】 填空 1:因为是 NN的矩阵,所以行列数是相同的 。第一个 for循环用来循环行,因此填入一个循环界限 N。 填空 2:此语句将移出矩阵的元素暂存,移出矩阵的元素的列下标为 N一 1,因此填入 N一 1。 填空 3:此语句将移出矩阵的元素放入最左边,也就是第一列,第一列元素的列下标为 0,因此填入 0。 二、程序修改题 2 【正确答案】 (1)sum=0 0; (2)if(i+1) 5=0) 【试题解析】 (1)变量 sum书写错误。 (2)循环条件 if(i+1 5=0)是一个运算逻辑错误,应先计算 i+1,再对 5求余。 三、程序设计题 3 【正确答案】 void fun(char*ss) int 1; for(i=0; ssi!=0; i+) *将 ss所指字符串中所有下标为奇数位置的字母 转换为大写 * if(i 2=1 &ssi =a &ssi =z ssi=ssi一 32; 【试题解析】 将指定字符串中奇数位置的字母转换为大写,首先需要判断奇数位置,再判断该位置字符是不是小写字母,如果是小写字母,则将小写字母转换为大写字母。字母大小写转换操作中,只要 将小写字母减去 32即可转换为大写字母。

展开阅读全文
相关资源
猜你喜欢
  • 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