【计算机类职业资格】二级C语言分类模拟题225及答案解析.doc

上传人:diecharacter305 文档编号:1325492 上传时间:2019-10-17 格式:DOC 页数:7 大小:40KB
下载 相关 举报
【计算机类职业资格】二级C语言分类模拟题225及答案解析.doc_第1页
第1页 / 共7页
【计算机类职业资格】二级C语言分类模拟题225及答案解析.doc_第2页
第2页 / 共7页
【计算机类职业资格】二级C语言分类模拟题225及答案解析.doc_第3页
第3页 / 共7页
【计算机类职业资格】二级C语言分类模拟题225及答案解析.doc_第4页
第4页 / 共7页
【计算机类职业资格】二级C语言分类模拟题225及答案解析.doc_第5页
第5页 / 共7页
点击查看更多>>
资源描述

1、二级 C语言分类模拟题 225及答案解析(总分:100.00,做题时间:90 分钟)一、程序填空题(总题数:1,分数:30.00)1.给定程序中,函数 fun的功能是:求 ss所指字符串数组中长度最短的字符串所在的行下标,作为函数值返回,并把其串长放在形参 n所指变量中。ss 所指字符串数组中共有 M个字符串,且串长N。 请在程序的下划线处填入正确的内容并把下划线删除,使程序得出正确的结果。 注意:源程序存放在 下的 BLANK1.C中。 不得增行或删行,也不得更改程序的结构! #include stdio.h #include string.h #define M 5 #define N 2

2、0 int fun(char (*ss) N, int *n) int i, k=0, len=N; /*found*/ for(i=0; i_; i+) len=strlen(ssi); if(i=0) *n=len; /*found*/ if (len _ *n) *n=len; k=i; /*found*/ return (_); main() char ssM N=“shanghai“,“guangzhou“,“beijing“,“tianjing“,“chongqing“; int n,k,i; printf(“/nThe original strings are :/n“); fo

3、r(i=0;iM;i+)puts(ssi); k=fun(ss, printf(“/nThe length of shortest string is:%d/n“,n); printf(“/nThe shortest string is:%s/n“,ssk); (分数:30.00)_二、程序修改题(总题数:1,分数:30.00)2.给定程序 MODI1.C中函数 fun的功能是:将 tt所指字符串中的小写字母都改为对应的大写字母,其他字符不变。 例如,若输入”Ab,cD”,则输出”AB,CD”。 请改正程序中的错误,使它能得出正确的结果。 注意:不要改动 main函数,不得增行或删行,也不得更

4、改程序的结构! #include stdio .h #include string.h char* fun(char tt) int i; for(i=0; tti; i+) /*found*/ if(“a“=tti)|(tti=“z“) /*found*/ tt i += 32; return (tt); main() char tt81; printf(“/nPlease enter a string:“); gets (tt); printf(“/nThe result string is:/n%s“, fun(tt); (分数:30.00)_三、程序设计题(总题数:1,分数:40.00

5、)3.请编写函数 fun,其功能是:将所有大于 1小于整数 m的非素数存入 xx所指数组中,非素数的个数通过k传回。 例如,若输入:17,则应输出:4 6 8 9 10 12 14 15 16。 注意:部分源程序在文件 PROG1.C中。 请勿改动主函数 main和其他函数中的任何内容,仅在函数 fun的花括号中填入你编写的若干语句。 #include stdio.h void fun(int m, int *k, int xx) main() int m, n, zz100; void NONO(); printf(“/nPlease enter an integer number betw

6、een 10 and 100:“); scanf(“%d“, fun(n, printf(“/n/nThere are %d nonprime numbers less than %d:“,m,n); for(n=0; nm; n+) printf (“/n %4d“, zzn); NONO(); void NONO() /* 请在此函数内打开文件,输入测试数据,调用 fun函数,输出数据,关闭文件。 */ int m, n, zz100; FILE *rf, *wf; rf=fopen(“in.dat“,“r“); wf=fopen(“out.dat“,“w“); fscanf(rf, “%

7、d“, fun(n, fprintf(wf, “%d/n%d/n“, m, n); for(n=0; nm; n+) fprintf(wf, “%d/n“, zzn); fclose(rf); fclose (wf); (分数:40.00)_二级 C语言分类模拟题 225答案解析(总分:100.00,做题时间:90 分钟)一、程序填空题(总题数:1,分数:30.00)1.给定程序中,函数 fun的功能是:求 ss所指字符串数组中长度最短的字符串所在的行下标,作为函数值返回,并把其串长放在形参 n所指变量中。ss 所指字符串数组中共有 M个字符串,且串长N。 请在程序的下划线处填入正确的内容并把

8、下划线删除,使程序得出正确的结果。 注意:源程序存放在 下的 BLANK1.C中。 不得增行或删行,也不得更改程序的结构! #include stdio.h #include string.h #define M 5 #define N 20 int fun(char (*ss) N, int *n) int i, k=0, len=N; /*found*/ for(i=0; i_; i+) len=strlen(ssi); if(i=0) *n=len; /*found*/ if (len _ *n) *n=len; k=i; /*found*/ return (_); main() cha

9、r ssM N=“shanghai“,“guangzhou“,“beijing“,“tianjing“,“chongqing“; int n,k,i; printf(“/nThe original strings are :/n“); for(i=0;iM;i+)puts(ssi); k=fun(ss, printf(“/nThe length of shortest string is:%d/n“,n); printf(“/nThe shortest string is:%s/n“,ssk); (分数:30.00)_正确答案:()解析:(1)M (2) (3)k 答案考生文件夹 解析 函数

10、fun的功能是求 ss所指字符串数组中长度最短的字符串所在的行下标。求最短字符串所在的下标,一般假设第一个字符串的长度最短 min,用 k记录最长字符串的下标的话,开始时 min=strlen(ss0),k=0,然后逐个比较其他字符串长度,如果字符串 ssi长度比 min小,则将 min赋值为这个字符串长度,“k=i”,如此便可求得最短字符串和最短字符串所在的下标位置。 第一空:循环的目的是在 M个字符串中寻找长度最短的字符串,因此循环变量 i从 0变化到“M-1”,故第一空处应为“M”。 第二空:“*n”记录最小字符串的长度,由审题分析可知,字符串 ssi长度比 min小,则交换最小长度值和

11、下标位置,故第二空处应为“”。 第三空:变量 k记录了最小字符串的下标位置,函数的返回值是最短的字符串所在的行下标,故第三空处应为“k”。 考点 指向一维数组的指针以及指针数组、运算符。二、程序修改题(总题数:1,分数:30.00)2.给定程序 MODI1.C中函数 fun的功能是:将 tt所指字符串中的小写字母都改为对应的大写字母,其他字符不变。 例如,若输入”Ab,cD”,则输出”AB,CD”。 请改正程序中的错误,使它能得出正确的结果。 注意:不要改动 main函数,不得增行或删行,也不得更改程序的结构! #include stdio .h #include string.h char*

12、 fun(char tt) int i; for(i=0; tti; i+) /*found*/ if(“a“=tti)|(tti=“z“) /*found*/ tt i += 32; return (tt); main() char tt81; printf(“/nPlease enter a string:“); gets (tt); printf(“/nThe result string is:/n%s“, fun(tt); (分数:30.00)_正确答案:()解析:(1)if(“a“=tti) 答案考生文件夹 解析 本题中函数的功能是将字符串中的小写字母改为对应的大写字母。首先判断字母

13、是否为小写字母,如果是小写字母则进行转换。 (1)第一个错误标识下的 if判断语句中的逻辑有误,应该是与(”改为“tti=32;”。 考点 指向一维数组的指针以及指针数组、if 语句及其构成的选择。三、程序设计题(总题数:1,分数:40.00)3.请编写函数 fun,其功能是:将所有大于 1小于整数 m的非素数存入 xx所指数组中,非素数的个数通过k传回。 例如,若输入:17,则应输出:4 6 8 9 10 12 14 15 16。 注意:部分源程序在文件 PROG1.C中。 请勿改动主函数 main和其他函数中的任何内容,仅在函数 fun的花括号中填入你编写的若干语句。 #include s

14、tdio.h void fun(int m, int *k, int xx) main() int m, n, zz100; void NONO(); printf(“/nPlease enter an integer number between 10 and 100:“); scanf(“%d“, fun(n, printf(“/n/nThere are %d nonprime numbers less than %d:“,m,n); for(n=0; nm; n+) printf (“/n %4d“, zzn); NONO(); void NONO() /* 请在此函数内打开文件,输入测

15、试数据,调用 fun函数,输出数据,关闭文件。 */ int m, n, zz100; FILE *rf, *wf; rf=fopen(“in.dat“,“r“); wf=fopen(“out.dat“,“w“); fscanf(rf, “%d“, fun(n, fprintf(wf, “%d/n%d/n“, m, n); for(n=0; nm; n+) fprintf(wf, “%d/n“, zzn); fclose(rf); fclose (wf); (分数:40.00)_正确答案:()解析:int i,j; int t=0; /初始化数组个数 for(i=2;im;i+) /循环判断小

16、于 n的数是否为素数 j=2; while (ji) if(i%j=0) /如果 i不是素数 xxt=i; t+; break; j+; *k=t; 答案考生文件夹 解析 该程序功能是将所有大于 1小于整数 m的非素数存入 xx所指数组中。求素数的常用方法是:从 2到 m-1去除 m,如果中间的任何数被整除,则不是素数。 (1)根据求素数的方法判断数 i是否为素数。 (2)把不是素数的数留下来,其方法是:如果该数是素数则不处理;如果不是素数则放到数组 xx中,并且把数组的下标加 1,为下一个不是素数的数放在数组中做准备。 (3)返回个数,把 xx数组中已经写入的数的个数返回即可,即把数组 xx的最大下标加 1返回即可。 考点 循环的嵌套、一维数组。

展开阅读全文
相关资源
猜你喜欢
  • BS ISO 13041-3-2009 Test conditions for numerically controlled turning machines and turning centres - Geometric tests for machines with inverted vertical workholding spindles《数控车床和.pdf BS ISO 13041-3-2009 Test conditions for numerically controlled turning machines and turning centres - Geometric tests for machines with inverted vertical workholding spindles《数控车床和.pdf
  • BS ISO 13041-4-2004 Test conditions for numerically controlled turning machines and turning centres - Accuracy and repeatability of positioning of linear and rotary axes《数控立式车床和旋转中.pdf BS ISO 13041-4-2004 Test conditions for numerically controlled turning machines and turning centres - Accuracy and repeatability of positioning of linear and rotary axes《数控立式车床和旋转中.pdf
  • BS ISO 13041-5-2015 Test conditions for numerically controlled turning machines and turning centres Accuracy of speeds and interpolations《数控旋转机床和旋转中心的试验条件 速度和插补精度》.pdf BS ISO 13041-5-2015 Test conditions for numerically controlled turning machines and turning centres Accuracy of speeds and interpolations《数控旋转机床和旋转中心的试验条件 速度和插补精度》.pdf
  • BS ISO 13041-6-2009 Test conditions for numerically controlled turning machines and turning centres - Accuracy of a finished test piece《数控车床和车削中心的试验条件 精加工试件的精度》.pdf BS ISO 13041-6-2009 Test conditions for numerically controlled turning machines and turning centres - Accuracy of a finished test piece《数控车床和车削中心的试验条件 精加工试件的精度》.pdf
  • BS ISO 13041-7-2004 Test conditions for numerically controlled turning machines and turning centres - Evaluation of contouring performance in the coordinate planes《数控立式车床和转向中心的试验条件.pdf BS ISO 13041-7-2004 Test conditions for numerically controlled turning machines and turning centres - Evaluation of contouring performance in the coordinate planes《数控立式车床和转向中心的试验条件.pdf
  • BS ISO 13041-8-2004 Test conditions for numerically controlled turning machines and turning centres - Evaluation of thermal distortions《数控立式车床和旋转中心的试验条件 热畸变的评价》.pdf BS ISO 13041-8-2004 Test conditions for numerically controlled turning machines and turning centres - Evaluation of thermal distortions《数控立式车床和旋转中心的试验条件 热畸变的评价》.pdf
  • BS ISO 13043-2011 Road vehicles Refrigerant systems used in mobile air conditioning systems (MAC) Safety requirements《道路车辆 移动空调系统(MAC)所使用的制冷系统 安全要求》.pdf BS ISO 13043-2011 Road vehicles Refrigerant systems used in mobile air conditioning systems (MAC) Safety requirements《道路车辆 移动空调系统(MAC)所使用的制冷系统 安全要求》.pdf
  • BS ISO 13044-1-2012 Road vehicles 24 V fully automatic coupling systems (FACS) for heavy commercial vehicle combinations General requirements and definitions《道路车辆 重型商用汽车组合用24 V全自动耦.pdf BS ISO 13044-1-2012 Road vehicles 24 V fully automatic coupling systems (FACS) for heavy commercial vehicle combinations General requirements and definitions《道路车辆 重型商用汽车组合用24 V全自动耦.pdf
  • BS ISO 13044-2-2013 Road vehicles Fully automatic coupling systems 24 V (FACS) for heavy commercial vehicle combinations 50 mm fifth wheel couplings Electrical and pneumatic interf.pdf BS ISO 13044-2-2013 Road vehicles Fully automatic coupling systems 24 V (FACS) for heavy commercial vehicle combinations 50 mm fifth wheel couplings Electrical and pneumatic interf.pdf
  • 相关搜索

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

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