【计算机类职业资格】全国计算机二级C语言上机试题32+2015年及答案解析.doc

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

1、全国计算机二级 C语言上机试题 32+2015年及答案解析(总分:30.00,做题时间:90 分钟)1.给定程序中,函数 fun的功能是:在形参 ss所指字符串数组中,将所有串长超过 k的字符串中右边的字符删除,只保留左边的 k个字符。ss 所指字符串数组中共有 N个字符串,且串长小于 M。 请在程序的下划线处填入正确的内容并把下划线删除, 使程序得出正确的结果。 注意:源程序存放在考生文件夹下的BLANK1.C中。不得增行或删行,也不得更改程序的结构! 给定源程序: #include #include #define N 5 #define M 10 /*found*/ void fun(c

2、har (*ss) _1_, int k) int i=0 ; /*found*/ while(ieps) s+=t; t=t * n/(2*n+1); n+; /*found*/ return(s); main() double x; printf(“/nPlease enter a precision: “); scanf(“%lf“, printf(“/neps=%lf, Pi=%lf/n/n“,x,fun(x); (分数:10.00)_3.假定输入的字符串中只包含字母和*号。请编写函数 fun,它的功能是:使字符串的前导*号不得多于 n个;若多于 n个,则删除多余的*号; 若少于或等于

3、 n个,则什么也不做,字符串中间和尾部的*号不删除。函数 fun中给出的语句仅供参考。 例如,字符串中的内容为:*A*BC*DEF*G*,若 n的值为 4,删除后,字符串中的内容应当是:*A*BC*DEF*G*;若 n的值为 8,则字符串中的内容仍为:*A*BC*DEF*G*。n 的值在主函数中输入。 在编写函数时,不得使用 C语言提供的字符串函数。 注意: 部分源程序在文件 PROG1.C文件中。请勿改动主函数 main和其它函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。 给定源程序: #include void fun( char *a, int n ) /* 以下代码仅

4、供参考 */ int i=0,j,k=0; while(ak=*) k+; /* k 为统计*字符个数 */ if(kn) i=n;j=k; /* 以下完成将下标为 k至串尾的字符前移 k-n个位置 */ main() char s81; int n; printf(“Enter a string:/n“);gets(s); printf(“Enter n : “);scanf(“%d“, fun( s,n ); printf(“The string after deleted:/n“);puts(s); NONO(); (分数:10.00)_全国计算机二级 C语言上机试题 32+2015年答

5、案解析(总分:30.00,做题时间:90 分钟)1.给定程序中,函数 fun的功能是:在形参 ss所指字符串数组中,将所有串长超过 k的字符串中右边的字符删除,只保留左边的 k个字符。ss 所指字符串数组中共有 N个字符串,且串长小于 M。 请在程序的下划线处填入正确的内容并把下划线删除, 使程序得出正确的结果。 注意:源程序存放在考生文件夹下的BLANK1.C中。不得增行或删行,也不得更改程序的结构! 给定源程序: #include #include #define N 5 #define M 10 /*found*/ void fun(char (*ss) _1_, int k) int

6、i=0 ; /*found*/ while(ieps) s+=t; t=t * n/(2*n+1); n+; /*found*/ return(s); main() double x; printf(“/nPlease enter a precision: “); scanf(“%lf“, printf(“/neps=%lf, Pi=%lf/n/n“,x,fun(x); (分数:10.00)_正确答案:(第一处: 初始化 t的值,根据程序中的计算程序和试题的要求得出,t 应为 1。 第二处: 根据公式 /2 得出,所以返回时应原有 s的基础上乘以 2作为返回值。)解析:3.假定输入的字符串中只

7、包含字母和*号。请编写函数 fun,它的功能是:使字符串的前导*号不得多于 n个;若多于 n个,则删除多余的*号; 若少于或等于 n个,则什么也不做,字符串中间和尾部的*号不删除。函数 fun中给出的语句仅供参考。 例如,字符串中的内容为:*A*BC*DEF*G*,若 n的值为 4,删除后,字符串中的内容应当是:*A*BC*DEF*G*;若 n的值为 8,则字符串中的内容仍为:*A*BC*DEF*G*。n 的值在主函数中输入。 在编写函数时,不得使用 C语言提供的字符串函数。 注意: 部分源程序在文件 PROG1.C文件中。请勿改动主函数 main和其它函数中的任何内容,仅在函数fun的花括号

8、中填入你编写的若干语句。 给定源程序: #include void fun( char *a, int n ) /* 以下代码仅供参考 */ int i=0,j,k=0; while(ak=*) k+; /* k 为统计*字符个数 */ if(kn) i=n;j=k; /* 以下完成将下标为 k至串尾的字符前移 k-n个位置 */ main() char s81; int n; printf(“Enter a string:/n“);gets(s); printf(“Enter n : “);scanf(“%d“, fun( s,n ); printf(“The string after deleted:/n“);puts(s); NONO(); (分数:10.00)_正确答案:(void fun( char *a, int n ) /* 以下代码仅供参考 */ int i=0,j,k=0; while(ak=*) k+; /* k为统计*字符个数 */ if(kn) i=n;j=k; /* 以下完成将下标为 k至串尾的字符前移k-n个位置 */ for(; aj !=0 ; j+) ai+=aj; ai = 0; )解析:

展开阅读全文
相关资源
猜你喜欢
  • BS ISO IEC 10746-3-2011 Information technology Open distributed processing Reference model Architecture《信息技术 开放分布处理 参照模式 体系结构》.pdf BS ISO IEC 10746-3-2011 Information technology Open distributed processing Reference model Architecture《信息技术 开放分布处理 参照模式 体系结构》.pdf
  • BS ISO IEC 10777-1992 Information technology - 3 81 mm wide magnetic tape cartridge for information interchange - Helical scan recording - DDS format《信息技术 信息交换用3 81mm宽磁带盒.pdf BS ISO IEC 10777-1992 Information technology - 3 81 mm wide magnetic tape cartridge for information interchange - Helical scan recording - DDS format《信息技术 信息交换用3 81mm宽磁带盒.pdf
  • BS ISO IEC 10861-1995 Information technology - Microprocessor systems - High-performance synchronous 32-bit bus MULTIBUS II《信息技术 微处理器系统 高性能同步32位总线 多总线Ⅱ》.pdf BS ISO IEC 10861-1995 Information technology - Microprocessor systems - High-performance synchronous 32-bit bus MULTIBUS II《信息技术 微处理器系统 高性能同步32位总线 多总线Ⅱ》.pdf
  • BS ISO IEC 10885-1994 Information technology - 356 mm optical disk cartridge for information interchange - Write once《信息技术 信息交换用356mm光盘盒 一次写入》.pdf BS ISO IEC 10885-1994 Information technology - 356 mm optical disk cartridge for information interchange - Write once《信息技术 信息交换用356mm光盘盒 一次写入》.pdf
  • BS ISO IEC 10918-2-1996 Information technology - Digital compression and coding of continuous-tone still images - Compliance testing《信息技术 连续色调静止成象的数字压缩和编码 合格试验》.pdf BS ISO IEC 10918-2-1996 Information technology - Digital compression and coding of continuous-tone still images - Compliance testing《信息技术 连续色调静止成象的数字压缩和编码 合格试验》.pdf
  • BS ISO IEC 10918-4-1999 Information technology - Digital compression and coding of continuous-tone still images - Registration of JPEG profiles SPIFF profiles SPIFF tags S.pdf BS ISO IEC 10918-4-1999 Information technology - Digital compression and coding of continuous-tone still images - Registration of JPEG profiles SPIFF profiles SPIFF tags S.pdf
  • BS ISO IEC 10967-1-2012 Information technology Language independent arithmetic Integer and floating point arithmetic《信息技术 语言独立计算 整数和浮点算法》.pdf BS ISO IEC 10967-1-2012 Information technology Language independent arithmetic Integer and floating point arithmetic《信息技术 语言独立计算 整数和浮点算法》.pdf
  • BS ISO IEC 10967-2-2001 Information technology Language independent arithmetic Elementary numerical functions《信息技术 独立于语言的算术 基本数值函数》.pdf BS ISO IEC 10967-2-2001 Information technology Language independent arithmetic Elementary numerical functions《信息技术 独立于语言的算术 基本数值函数》.pdf
  • BS ISO IEC 10967-3-2007 Information technology - Language independent arithmetric - Complex integer and floating point arithmetic and complex elementary numerical function.pdf BS ISO IEC 10967-3-2007 Information technology - Language independent arithmetric - Complex integer and floating point arithmetic and complex elementary numerical function.pdf
  • 相关搜索

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

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