【计算机类职业资格】全国计算机等级考试二级C语言上机题库试卷十2013年3月及答案解析.doc

上传人:Iclinic170 文档编号:1329656 上传时间:2019-10-17 格式:DOC 页数:2 大小:29.50KB
下载 相关 举报
【计算机类职业资格】全国计算机等级考试二级C语言上机题库试卷十2013年3月及答案解析.doc_第1页
第1页 / 共2页
【计算机类职业资格】全国计算机等级考试二级C语言上机题库试卷十2013年3月及答案解析.doc_第2页
第2页 / 共2页
亲,该文档总共2页,全部预览完了,如果喜欢就下载吧!
资源描述

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

2、include #define N 3 int fun(int (*a)N) int i,j,m1,m2,row,colum; m1=m2=0; for(i=0; i_2.给定程序 MODI1.C中 fun函数的功能是: 根据整型形参 m,计算如下公式的值。 1 1 1 t = 1 - - - - - - - 2 3 m 例如,若主函数中输入 5,则应输出 -0.283333。 请改正函数 fun中的错误或在横线处填上适当的内容并把横线删除, 使它能计算出正确的结果。 注意:不要改动 main 函数,不得增行或删行,也不得更改程序的结构! 给定源程序: #include double fun(

3、 int m ) double t = 1.0; int i; for( i = 2; i = m; i+ ) t = 1.0-1 /i; _; main() int m ; printf( “/nPlease enter 1 integer numbers:/n“ ); scanf( “%d“, printf( “/n/nThe result is %lf/n“, fun( m ) ); (分数:1.00)_3.请编写一个函数,函数的功能是删除字符串中的所有空格。 例如, 主函数中输入“asd af aa z67“, 则输出为 “asdafaaz67“。 注意:部分源程序在文件 PROG1.

4、C中。 请勿改动主函数 main和其它函数中的任何内容,仅在函数 fun的花括号中填入你编写的若干语句。 给定源程序: #include #include int fun(char *str) main() char str81; int n; printf(“Input a string:“) ; gets(str); puts(str); fun(str); printf(“* str: %s/n“,str); NONO(); (分数:1.00)_全国计算机等级考试二级 C语言上机题库试卷十 2013年 3月答案解析(总分:3.00,做题时间:90 分钟)1.给定程序中,函数 fun的功能

5、是:判定形参 a所指的 NN(规定 N为奇数)的矩阵是否是“幻方“,若是,函数返回值为 1; 不是,函数返回值为 0。“幻方“的判定条件是:矩阵每行、每列、主对角线及反对角线上元素之和都相等。 例如,以下 33的矩阵就是一个“幻方“: 4 9 2 3 5 7 8 1 6 请在程序的下划线处填入正确的内容并把下划线删除, 使程序得出正确的结果。 注意:源程序存放在考生文件夹下的BLANK1.C中。不得增行或删行,也不得更改程序的结构! 给定源程序: #include #define N 3 int fun(int (*a)N) int i,j,m1,m2,row,colum; m1=m2=0;

6、for(i=0; i_正确答案:()解析:第一处:行列变量 row和 colum的值初始化为 0。 第二处:两个条件只要有一个不满足就返回 0,所以应填:|。 第三处:如果矩阵是“幻方”,则返回 1。2.给定程序 MODI1.C中 fun函数的功能是: 根据整型形参 m,计算如下公式的值。 1 1 1 t = 1 - - - - - - - 2 3 m 例如,若主函数中输入 5,则应输出 -0.283333。 请改正函数 fun中的错误或在横线处填上适当的内容并把横线删除, 使它能计算出正确的结果。 注意:不要改动 main 函数,不得增行或删行,也不得更改程序的结构! 给定源程序: #inc

7、lude double fun( int m ) double t = 1.0; int i; for( i = 2; i = m; i+ ) t = 1.0-1 /i; _; main() int m ; printf( “/nPlease enter 1 integer numbers:/n“ ); scanf( “%d“, printf( “/n/nThe result is %lf/n“, fun( m ) ); (分数:1.00)_正确答案:()解析:第一处:在除法运算中,如果除数和被除数都是整数,所么所除结果也是整数,因此应改为 t-=1./i。 第二处:应是返回公式的值,函数中公

8、式的值是存放在临时变量 t中,所以应填 return t;。3.请编写一个函数,函数的功能是删除字符串中的所有空格。 例如, 主函数中输入“asd af aa z67“, 则输出为 “asdafaaz67“。 注意:部分源程序在文件 PROG1.C中。 请勿改动主函数 main和其它函数中的任何内容,仅在函数 fun的花括号中填入你编写的若干语句。 给定源程序: #include #include int fun(char *str) main() char str81; int n; printf(“Input a string:“) ; gets(str); puts(str); fun(

9、str); printf(“* str: %s/n“,str); NONO(); (分数:1.00)_正确答案:(int fun(char *str) char *p = str ; int i = 0 ; while(*p) if(*p != ) stri+ = *p ; p+ ; stri = 0 ; )解析:本题是考察考生怎样利用字符串指针来删除字符串的空格字符。在函数开始处把指针 p先指 向字符串 str以及位置变量 i置 0,然后采用 while循环和字符串指针 p来处理的,每循环一次来判断指针 p所指的字符是否为空格,如果不是空格,则把该字符写到 str字符串中,位置由 i来控制,如果是空格,则不处理,继续取下一字符,直至字符串结束为止,最后再把字符串结束符写到位置为 i的 str上,再通过形参 str返回。

展开阅读全文
相关资源
猜你喜欢
  • BS EN ISO 10438-4-2008 Petroleum petrochemical and natural gas industries - Lubrication shaft-sealing and control-oil systems and auxiliaries - Self-acting gas seal support systems.pdf BS EN ISO 10438-4-2008 Petroleum petrochemical and natural gas industries - Lubrication shaft-sealing and control-oil systems and auxiliaries - Self-acting gas seal support systems.pdf
  • BS EN ISO 10439-1-2015 Petroleum petrochemical and natural gas industries Axial and centrifugal compressors and expander-compressors General requirements《石油 石化和天然气工业 轴向和离心式压缩机以及膨胀机.pdf BS EN ISO 10439-1-2015 Petroleum petrochemical and natural gas industries Axial and centrifugal compressors and expander-compressors General requirements《石油 石化和天然气工业 轴向和离心式压缩机以及膨胀机.pdf
  • BS EN ISO 10439-2-2015 Petroleum petrochemical and natural gas industries Axial and centrifugal compressors and expander-compressors Non-integrally geared centrifugal and axial com.pdf BS EN ISO 10439-2-2015 Petroleum petrochemical and natural gas industries Axial and centrifugal compressors and expander-compressors Non-integrally geared centrifugal and axial com.pdf
  • BS EN ISO 10439-3-2015 Petroleum petrochemical and natural gas industries Axial and centrifugal compressors and expander-compressors Integrally geared centrifugal compressors《石油 石化.pdf BS EN ISO 10439-3-2015 Petroleum petrochemical and natural gas industries Axial and centrifugal compressors and expander-compressors Integrally geared centrifugal compressors《石油 石化.pdf
  • BS EN ISO 10439-4-2015 Petroleum petrochemical and natural gas industries Axial and centrifugal compressors and expander-compressors Expander-compressors《石油 石化和天然气工业 轴向和离心式压缩机以及膨胀机.pdf BS EN ISO 10439-4-2015 Petroleum petrochemical and natural gas industries Axial and centrifugal compressors and expander-compressors Expander-compressors《石油 石化和天然气工业 轴向和离心式压缩机以及膨胀机.pdf
  • BS EN ISO 10440-1-2008 Petroleum petrochemical and natural gas industries Rotary-type positive-displacement compressors Process compressors《石油 石化和天然气工业 旋转型容积式压缩机 加工压缩机》.pdf BS EN ISO 10440-1-2008 Petroleum petrochemical and natural gas industries Rotary-type positive-displacement compressors Process compressors《石油 石化和天然气工业 旋转型容积式压缩机 加工压缩机》.pdf
  • BS EN ISO 10440-2-2002 Petroleum and natural gas industries Rotary-type positive-displacement compressors Packaged air compressors (oil-free)《石油和天然气工业 旋转型容积式压缩机 封装的空气压缩机(无油)》.pdf BS EN ISO 10440-2-2002 Petroleum and natural gas industries Rotary-type positive-displacement compressors Packaged air compressors (oil-free)《石油和天然气工业 旋转型容积式压缩机 封装的空气压缩机(无油)》.pdf
  • BS EN ISO 10441-2007 Petroleum petrochemical and natural gas industries - Flexible couplings for mechanical power transmission - Special-purpose applications《石油、石化和天然气工业 机械动力传输用挠性联.pdf BS EN ISO 10441-2007 Petroleum petrochemical and natural gas industries - Flexible couplings for mechanical power transmission - Special-purpose applications《石油、石化和天然气工业 机械动力传输用挠性联.pdf
  • BS EN ISO 10442-2003 Petroleum chemical and gas service industries - Packaged integrally geared centrifugal air compressors《石油、化学和气体工业 整体封装齿轮传动离心空气压缩机》.pdf BS EN ISO 10442-2003 Petroleum chemical and gas service industries - Packaged integrally geared centrifugal air compressors《石油、化学和气体工业 整体封装齿轮传动离心空气压缩机》.pdf
  • 相关搜索

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

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