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

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

1、二级 C 语言机试-31 及答案解析(总分:100.00,做题时间:90 分钟)一、填空题(总题数:1,分数:33.00)1.请补充函数 fun(),该函数的功能是:分类统计一个字符串中元音字母和其他字符的个数(不区分大小写)。例如,输入 aeiouAOUpqrt,结果为 A2 E1 I1 O2 U2 Other4。注意:部分源程序给出如下。请勿改动主函数 main 和其他函数中的任何内容,仅在函数 fun()的横线上填入所编写的若干表达式或语句。试题程序:#includestdioh#includeconioh#define N 100void fun(char *str,int bb )c

2、har *p=str;int i=0;for(i=0;i6;i+)【1】 ;while(*p)switch(*p)case A:case a:bb0+;break;case E:case e:bb1+;break;case I:case i:bb2+;break;case O:case o:bb3+;break;case U:case u:bb4+;break;default: 【2】 ;【3】 main()char strN,ss6=“AEIOU“;int i;int bb6;clrscr();printf(“Input a string:/n“); gets(str);printf(“th

3、e string is:/n“);puts(str);fun(str,bb);for(i=0;i5;i+)printf(“/n%c:%d“,ssi,bbi);printf(“/nother:%d“,bbi);(分数:33.00)填空项 1:_二、改错题(总题数:1,分数:33.00)2.下列给定的程序中,函数 fun()的功能是:计算并输出 k 以内最大的 6 个能被 7 或 11 整除的自然数之和。K 的值由主函数传入,若 k 的值为 500,则函数的值为 2925。请改正程序中的错误,使它能得到正确结果。注意:不要改动 main 函数,不得增行或删行,也不得更改程序的结构。试题程序:#in

4、cludestdioh#include coniohint fun(int k)int m=0,mc=0,j;/*found*/while(k=2)int bb6;clrscr();printf(“Input a string:/n“); gets(str);printf(“the string is:/n“);puts(str);fun(str,bb);for(i=0;i5;i+)printf(“/n%c:%d“,ssi,bbi);printf(“/nother:%d“,bbi);(分数:33.00)填空项 1:_ (正确答案:1 bbi=0 2 bb5+ 3 p+;)解析:解析 填空 1:

5、数组 bb6用来存放 5 个元音字母和其他字符的个数,在使用之前需要清零。填空2:数组元素 bb5用来存放其他字符的个数,当指针 p 所指的字符不是元音字母时,则认为是其他字符,bb5加 1。填空 3:指针 p 指向字符串 str,通过 p 自加 1 来移动指针,访问字符串中的所有字符。二、改错题(总题数:1,分数:33.00)2.下列给定的程序中,函数 fun()的功能是:计算并输出 k 以内最大的 6 个能被 7 或 11 整除的自然数之和。K 的值由主函数传入,若 k 的值为 500,则函数的值为 2925。请改正程序中的错误,使它能得到正确结果。注意:不要改动 main 函数,不得增行

6、或删行,也不得更改程序的结构。试题程序:#includestdioh#include coniohint fun(int k)int m=0,mc=0,j;/*found*/while(k=2)&(mc6)/*found*/if(k%7=0)|(k%ll=0)/*found*/m=k;mc+;k-;return m;main()clrscr();printf(“%d/n“,fun(500);(分数:33.00)填空项 1:_ (正确答案:(1)错误:while(k=2)&(mc6) 正确:while(k=2)&(mc6)(2) 错误:if(k%7=0)|(k%11=0) 正确:if(k%7=0

7、)|(k%110)(3) 错误:m=k 正确:m=m+k;)解析:解析 错误 1:C 语言规定 while 语句后的表达式两侧必须要有圆括号。错误 2:if 语句的判断条件应用关系运算符,而不是赋值运算符。错误 3:根据题意,将满足条件的数求累加和。三、编程题(总题数:1,分数:34.00)3.请编写一个函数 fun(),它的功能是:将 ss 所指字符串中所有下标为偶数位置的字母转换为小写(若该位置上不是字母,则不转换)。例如,若输入 ABC4efG,则应输出 aBc4efg。注意:部分源程序给出如下。请勿改动主函数 miain 和其他函数中的任何内容,仅在函数 fun 的花括号中填入所编写的

8、若干语句。试题程序:#includeconioh#includestdioh#includestringh void fun(char *ss)main()char tt81;clrscr();printf(“/nPlease enter an string within 80characters:/n“);gets(tt);printf(“/n/nAfter changing,the string/n/%s“,tt);fun(tt);printf(“/nbecomes/n /%s/n“,tt);(分数:34.00)_正确答案:(void fun(char *ss)int i;for(i=0;ssi!=/0i+) /*将 ss 所指字符串中所有下标为偶数位置的字母转换为小写*/if(i%2=0&ssi=A&ssi=z)ssi=ssi+32;)解析:解析 从 C 语言的学习中我们知道,只要将小写字母减去 32 则转成大写字母,将大写字母加上32 则转成小写字母。该程序是用 if 语句实现该功能转化的。

展开阅读全文
相关资源
猜你喜欢
  • ANSI TIA-825-A-2003 A Frequency Shift Keyed Modem for Use on the Public Switched Telephone Network《公共交换电话网上使用的频移键控调制解调器》.pdf ANSI TIA-825-A-2003 A Frequency Shift Keyed Modem for Use on the Public Switched Telephone Network《公共交换电话网上使用的频移键控调制解调器》.pdf
  • ANSI TIA-855-A-2011 Telecommunications Telephone Terminal Equipment Stutter Dial Tone Detection Device Performance Requirements《通讯.电话终端设备.黑白干扰拨号音检测设备.性能要求》.pdf ANSI TIA-855-A-2011 Telecommunications Telephone Terminal Equipment Stutter Dial Tone Detection Device Performance Requirements《通讯.电话终端设备.黑白干扰拨号音检测设备.性能要求》.pdf
  • ANSI TIA-862-B-1-2017 Structured Cabling Infrastructure Standard for Intelligent Building Systems Addendum 1 Updated References Accommodation of New Media Types (Addendum to TIA-86.pdf ANSI TIA-862-B-1-2017 Structured Cabling Infrastructure Standard for Intelligent Building Systems Addendum 1 Updated References Accommodation of New Media Types (Addendum to TIA-86.pdf
  • ANSI TIA-862-B-2016 Structured Cabling Infrastructure Standard for Intelligent Building Systems.pdf ANSI TIA-862-B-2016 Structured Cabling Infrastructure Standard for Intelligent Building Systems.pdf
  • ANSI TIA-876-2002 North American Network Access Transmission Model for Evaluating xDSL Modem Performance《xDSL调制解调器性能评定用的北美网络接入传输模式》.pdf ANSI TIA-876-2002 North American Network Access Transmission Model for Evaluating xDSL Modem Performance《xDSL调制解调器性能评定用的北美网络接入传输模式》.pdf
  • ANSI TIA-902.BAAB-A-2003 Wideband Air Interface Scalable Adaptive Modulation (SAM) Physical Layer Specification-Public Safety Wideband Data Standards Project- Digital Radio Technic.pdf ANSI TIA-902.BAAB-A-2003 Wideband Air Interface Scalable Adaptive Modulation (SAM) Physical Layer Specification-Public Safety Wideband Data Standards Project- Digital Radio Technic.pdf
  • ANSI TIA-902.BAAC-A-2007 Wideband Air Interface Media Access Control Radio Link Adaptation (MAC RLA) Layer Specification《宽带远程空中接口媒体准入控制 无线电通信链路适配(MAC RLA)层规范》.pdf ANSI TIA-902.BAAC-A-2007 Wideband Air Interface Media Access Control Radio Link Adaptation (MAC RLA) Layer Specification《宽带远程空中接口媒体准入控制 无线电通信链路适配(MAC RLA)层规范》.pdf
  • ANSI TIA-902.BAAD-A-2003 Wideband Air Interface Scalable Adaptive Modulation (SAM) Radio Channel Coding Specification- Public Safety Wideband Data Standards Project- Digital Radio .pdf ANSI TIA-902.BAAD-A-2003 Wideband Air Interface Scalable Adaptive Modulation (SAM) Radio Channel Coding Specification- Public Safety Wideband Data Standards Project- Digital Radio .pdf
  • ANSI TIA-902.BAAE-A-2002 Wideband Air Interface - Logical Link Control (LLC) Layer Specification - Public Safety Wideband Data Standards Project - Digital Radio Technical Standards.pdf ANSI TIA-902.BAAE-A-2002 Wideband Air Interface - Logical Link Control (LLC) Layer Specification - Public Safety Wideband Data Standards Project - Digital Radio Technical Standards.pdf
  • 相关搜索

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

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