【计算机类职业资格】二级C语言-289及答案解析.doc

上传人:sumcourage256 文档编号:1325140 上传时间:2019-10-17 格式:DOC 页数:5 大小:35.50KB
下载 相关 举报
【计算机类职业资格】二级C语言-289及答案解析.doc_第1页
第1页 / 共5页
【计算机类职业资格】二级C语言-289及答案解析.doc_第2页
第2页 / 共5页
【计算机类职业资格】二级C语言-289及答案解析.doc_第3页
第3页 / 共5页
【计算机类职业资格】二级C语言-289及答案解析.doc_第4页
第4页 / 共5页
【计算机类职业资格】二级C语言-289及答案解析.doc_第5页
第5页 / 共5页
亲,该文档总共5页,全部预览完了,如果喜欢就下载吧!
资源描述

1、二级 C 语言-289 及答案解析(总分:100.00,做题时间:90 分钟)一、程序填空题(总题数:1,分数:30.00)1.给定程序中,函数 fun 的功能是:判定形参 a 所指的 NN(规定 N 为奇数)的矩阵是否是“幻方”,若是,函数返回值为 1;不是,函数返回值为 0。“幻方”的判定条件是:矩阵每行、每列、主对角线及反对角线上元素之和都相等。 例如,以下 33 的矩阵就是一个“幻方”: 4 9 2 3 5 7 8 1 6 请在程序的下划线处填入正确的内容并把下划线删除,使程序得出正确的结果。 不得增行或删行,也不得更改程序的结构! 给定源程序: #includestdio.h #de

2、fine N 3 int fun(int(*a)N) int i, j, m1, m2, row, colum; m1=m2=0; for(i=0; iN; i+) j=N-i-1; m1+=aii; m2+=aij; if(m1!=m2) return 0; for(i=0; iN; i+) /*found*/ row=colum= 1; for(j=0; jN; j+) row+=aij; colum+=aji; /*found*/ if(row!=colum) 2(row!=m1) return 0; /*found*/ return 3; main() int xNN, i, j; p

3、rintf(“Enter number for array:/n“); for(i=0; iN; i+) for(j=0; jN; j+)scanf(“%d“, printf(“Array:/n“); for(i=0; iN; i+) for(j=0; jN; j+)printf(“%3d“, xij); printf(“/n“); if(fun(x)printf(“The Array is a magic square./n“); else printf(“The Array isn“t a magic square./n“); (分数:30.00)二、程序改错题(总题数:1,分数:30.0

4、0)2.给定程序中 fun 函数的功能是:根据整型形参 m,计算如下公式的值。 (分数:30.00)三、程序设计题(总题数:1,分数:40.00)3.请编写一个函数,函数的功能是删除字符串中的所有空格。 例如,主函数中输入“asd af aa z67”,则输出为“asdafaaz67”。 请勿改动主函数 main 和其它函数中的任何内容,仅在函数 fun 的花括号中填入你编写的若干语句。 给定源程序: #includestdio.h #includectype.h void fun(char*str) main() char str81; printf(“Input a string:“);

5、gets(str); puts(str); fun(str); printf(“*str:%s/n“, str); (分数:40.00)_二级 C 语言-289 答案解析(总分:100.00,做题时间:90 分钟)一、程序填空题(总题数:1,分数:30.00)1.给定程序中,函数 fun 的功能是:判定形参 a 所指的 NN(规定 N 为奇数)的矩阵是否是“幻方”,若是,函数返回值为 1;不是,函数返回值为 0。“幻方”的判定条件是:矩阵每行、每列、主对角线及反对角线上元素之和都相等。 例如,以下 33 的矩阵就是一个“幻方”: 4 9 2 3 5 7 8 1 6 请在程序的下划线处填入正确的

6、内容并把下划线删除,使程序得出正确的结果。 不得增行或删行,也不得更改程序的结构! 给定源程序: #includestdio.h #define N 3 int fun(int(*a)N) int i, j, m1, m2, row, colum; m1=m2=0; for(i=0; iN; i+) j=N-i-1; m1+=aii; m2+=aij; if(m1!=m2) return 0; for(i=0; iN; i+) /*found*/ row=colum= 1; for(j=0; jN; j+) row+=aij; colum+=aji; /*found*/ if(row!=col

7、um) 2(row!=m1) return 0; /*found*/ return 3; main() int xNN, i, j; printf(“Enter number for array:/n“); for(i=0; iN; i+) for(j=0; jN; j+)scanf(“%d“, printf(“Array:/n“); for(i=0; iN; i+) for(j=0; jN; j+)printf(“%3d“, xij); printf(“/n“); if(fun(x)printf(“The Array is a magic square./n“); else printf(“

8、The Array isn“t a magic square./n“); (分数:30.00)解析:(1)0 (2)| (3)1 解析 填空 1:本题考查为变量赋初值,在这里 row+=aij代表是每行的总和,colum+=aji代表的是每列的总和,因而 row,colum 在初始化时应该为零,此空应该填 0。 填空 2:本题考查了 if 条件语句,此句 if 判断代表每行的总和与列是否相等,每行的总和是否与对角线的总和相等,两者若有一个不成立,即返回 0,因而此空应该填写|。 填空 3:题目要求若矩阵是”幻方”,则函数返回值为 1,因而此空应该填写 1。二、程序改错题(总题数:1,分数:30

9、00)2.给定程序中 fun 函数的功能是:根据整型形参 m,计算如下公式的值。 (分数:30.00)解析:(1)t-=1.0/i; (2)return t; 解析 (1)变量 t 存放公式的和,通过循环语句进行复合运算,因此此处应改为 t-=1.0/i;,注意此处应进行变量的类型转换。 (2)循环结束后应将和值返回给主函数。三、程序设计题(总题数:1,分数:40.00)3.请编写一个函数,函数的功能是删除字符串中的所有空格。 例如,主函数中输入“asd af aa z67”,则输出为“asdafaaz67”。 请勿改动主函数 main 和其它函数中的任何内容,仅在函数 fun 的花括号中填

10、入你编写的若干语句。 给定源程序: #includestdio.h #includectype.h void fun(char*str) main() char str81; printf(“Input a string:“); gets(str); puts(str); fun(str); printf(“*str:%s/n“, str); (分数:40.00)_正确答案:()解析:void fun(char *str) int i=0; char *p=str; while(*p) if(*p!=“) /*删除空格*/ stri=*p; i+; p+; stri=“/0“; /*加上结束符*/ 解析 本题要求删除所有空格,即保留除了空格以外的其他所有字符。由于 C 语言中没有直接删除字符的操作,所以对不需要删除的字符采用”保留”的操作。用指针 p 指向字符串中的每一个字符,每指向到一个字符都判断其是否为空格,若不是空格则保存到 stri。

展开阅读全文
相关资源
猜你喜欢
  • ASTM D5806-1995(2009) 7500 Standard Test Method for Disinfectant Quaternary Ammonium Salts by Potentiometric Titration《用滴定计滴定法测定氨基盐消毒要素的标准试验方法》.pdf ASTM D5806-1995(2009) 7500 Standard Test Method for Disinfectant Quaternary Ammonium Salts by Potentiometric Titration《用滴定计滴定法测定氨基盐消毒要素的标准试验方法》.pdf
  • ASTM D5806-1995(2017) 0788 Standard Test Method for Disinfectant Quaternary Ammonium Salts by Potentiometric Titration《用电位滴定法测定消毒剂季铵盐的标准试验方法》.pdf ASTM D5806-1995(2017) 0788 Standard Test Method for Disinfectant Quaternary Ammonium Salts by Potentiometric Titration《用电位滴定法测定消毒剂季铵盐的标准试验方法》.pdf
  • ASTM D5807-2002a(2007) Standard Practice for Evaluating the Overpressurization Characteristics of Inflatable Restraint Cushions《膨胀抑制垫的过量增压特性的评估的标准规程》.pdf ASTM D5807-2002a(2007) Standard Practice for Evaluating the Overpressurization Characteristics of Inflatable Restraint Cushions《膨胀抑制垫的过量增压特性的评估的标准规程》.pdf
  • ASTM D5807-2008 516 Standard Practice for Evaluating the Overpressurization Characteristics of Inflatable Restraint Cushions《可充气缓冲垫的过压特性评定的标准规范》.pdf ASTM D5807-2008 516 Standard Practice for Evaluating the Overpressurization Characteristics of Inflatable Restraint Cushions《可充气缓冲垫的过压特性评定的标准规范》.pdf
  • ASTM D5807-2008(2013) 2500 Standard Practice for Evaluating the Overpressurization Characteristics of Inflatable Restraint Cushions《评估可充气缓冲垫过压特性的标准实施规程》.pdf ASTM D5807-2008(2013) 2500 Standard Practice for Evaluating the Overpressurization Characteristics of Inflatable Restraint Cushions《评估可充气缓冲垫过压特性的标准实施规程》.pdf
  • ASTM D5807-2018 6875 Standard Practice for Evaluating the Overpressurization Characteristics of Inflatable Restraint Cushions.pdf ASTM D5807-2018 6875 Standard Practice for Evaluating the Overpressurization Characteristics of Inflatable Restraint Cushions.pdf
  • ASTM D5808-2003 Standard Test Method for Determining Organic Chloride in Aromatic Hydrocarbons and Related Chemicals by Microcoulometry《用微库仑分析法测定芳香烃和相关化学药品中有机氯的标准试验方法》.pdf ASTM D5808-2003 Standard Test Method for Determining Organic Chloride in Aromatic Hydrocarbons and Related Chemicals by Microcoulometry《用微库仑分析法测定芳香烃和相关化学药品中有机氯的标准试验方法》.pdf
  • ASTM D5808-2009 374 Standard Test Method for Determining Chloride in Aromatic Hydrocarbons and Related Chemicals by Microcoulometry.pdf ASTM D5808-2009 374 Standard Test Method for Determining Chloride in Aromatic Hydrocarbons and Related Chemicals by Microcoulometry.pdf
  • ASTM D5808-2009a 6250 Standard Test Method for Determining Chloride in Aromatic Hydrocarbons and Related Chemicals by Microcoulometry《用微库仑分析法测定芳香烃和相关化学药品中氯的标准试验方法》.pdf ASTM D5808-2009a 6250 Standard Test Method for Determining Chloride in Aromatic Hydrocarbons and Related Chemicals by Microcoulometry《用微库仑分析法测定芳香烃和相关化学药品中氯的标准试验方法》.pdf
  • 相关搜索

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

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