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

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

1、二级 C 语言-172 (1)及答案解析(总分:100.00,做题时间:90 分钟)一、程序填空题(总题数:1,分数:30.00)1.请补充函数 proc(),该函数的功能是:只保留字符串中的大写字母,删除其他字符,结果仍保存在原来的字符串中,由全局变量 m 对删除后字符串的长度进行保存。 注意:部分源程序给出如下。 请勿改动 main()函数和其他函数中的任何内容,仅在函数 proc()的横线上填入所编写的若干表达式或语句。 试题程序: #includestdlib.h #includestdlib.h #includeconio.h int m; void proc(char*str) i

2、nt i=0, j=0; char*p=str; while(*(p+i) if(*(p+i)=“A“ 2; strj=“/0“; 3; void main() char str80; system(“CLS“); printf(“/nEnter a string: “); gets(str); printf(“/n/nThe string is: %s/n“, str); proc(str); printf(“/n/nThe string of changing is: %s/n“, str); printf(“/n/nThe length of changed string is: %d/

3、n“, m); (分数:30.00)二、程序改错题(总题数:1,分数:40.00)2.下列给定程序中 proc()函数的功能是:将 n 个无序整数按从小到大排序。 请修改程序中的错误,使它能得出正确的结果。 注意:不要改动 main()函数,不得增行或删行,也不得更改程序的结构。 试题程序: #includeconio.h #includestdlib.h #includestdio.h void proc(int n,int *arr) int i, j, p, t; for(j=0; jn-1; j+) p=j; /*found* for(i=j+1; in-1; i+) if(arrpa

4、rri) /*found* t=i; if(p!=j) t=arrj; arrj=arrp; arrp=t; void putarr(int n, int*z) int i; for(i=1; i=n; i+, z+) printf(“%4d“, *z); if(!(i%10) printf(“/n“); printf(“/n“); void main() int arr20=9, 3, 0, 4, 1, 2, 5, 6, 8, 10, 7, n=11; system(“CLS“); printf(“/n/nBefore sorting %d numbers: /n“, n); putarr(

5、n, arr); proc(n, arr); printf(“/nAfter sorting %d numbers: /n“, n); putarr(n, arr); (分数:40.00)_三、程序设计题(总题数:1,分数:30.00)3.请编写一个函数 int proc(int*s,int t,int*k),用来求出数组的最大元素在数组中的下标并存放在k 所指的存储单元中。 例如,输入如下整数: 876 675 896 101 999 401 980 431 451 777 则输出结果为 4,999。 注意:部分源程序给出如下。 请勿改动 main()函数和其他函数中的任何内容,仅在函数 p

6、roc()的花括号中填入所编写的若干语句。 试题程序: #includestdlib.h #includeconio.h #includestdio.h int proc(int*s, int t, int*k) void main() int arr10=876, 675, 896, 101, 999, 401, 980, 431, 451, 777, k; system(“CLS“); proc(arr, 10, printf(“%d, %d/n“, k, arrk); (分数:30.00)_二级 C 语言-172 (1)答案解析(总分:100.00,做题时间:90 分钟)一、程序填空题(

7、总题数:1,分数:30.00)1.请补充函数 proc(),该函数的功能是:只保留字符串中的大写字母,删除其他字符,结果仍保存在原来的字符串中,由全局变量 m 对删除后字符串的长度进行保存。 注意:部分源程序给出如下。 请勿改动 main()函数和其他函数中的任何内容,仅在函数 proc()的横线上填入所编写的若干表达式或语句。 试题程序: #includestdlib.h #includestdlib.h #includeconio.h int m; void proc(char*str) int i=0, j=0; char*p=str; while(*(p+i) if(*(p+i)=“A

8、 2; strj=“/0“; 3; void main() char str80; system(“CLS“); printf(“/nEnter a string: “); gets(str); printf(“/n/nThe string is: %s/n“, str); proc(str); printf(“/n/nThe string of changing is: %s/n“, str); printf(“/n/nThe length of changed string is: %d/n“, m); (分数:30.00)解析:strj+=*(p+i) i+ m=j解析 根据题目要求将

9、字符串中的每一个大写字母放在原来的字符串中,因此,第一处填“strj+=*(p+i)”;变量 i 存放字符串中每一个字符对于字符串头指针的偏移量,每做一次循环要向后移动一个字符,因此,第二处填“i+”;变量 j 为新的字符串下标的最大值,也就是字符串的长度,题目要求字符串的长度由全局变量进行保存,因此,第三处填“m=j”。二、程序改错题(总题数:1,分数:40.00)2.下列给定程序中 proc()函数的功能是:将 n 个无序整数按从小到大排序。 请修改程序中的错误,使它能得出正确的结果。 注意:不要改动 main()函数,不得增行或删行,也不得更改程序的结构。 试题程序: #includec

10、onio.h #includestdlib.h #includestdio.h void proc(int n,int *arr) int i, j, p, t; for(j=0; jn-1; j+) p=j; /*found* for(i=j+1; in-1; i+) if(arrparri) /*found* t=i; if(p!=j) t=arrj; arrj=arrp; arrp=t; void putarr(int n, int*z) int i; for(i=1; i=n; i+, z+) printf(“%4d“, *z); if(!(i%10) printf(“/n“); pr

11、intf(“/n“); void main() int arr20=9, 3, 0, 4, 1, 2, 5, 6, 8, 10, 7, n=11; system(“CLS“); printf(“/n/nBefore sorting %d numbers: /n“, n); putarr(n, arr); proc(n, arr); printf(“/nAfter sorting %d numbers: /n“, n); putarr(n, arr); (分数:40.00)_正确答案:()解析:(1)错误:for(i=j+1; in-1; i+) 正确:for(i=j+1; in; i+) (2

12、)错误:t=i; 正确:p=i; 解析 要将 n 个无序整数从小到大排序,需要将数组中的每一元素与其后的各个元素相比较,因此,“for(i=j+1; in-1; i+)”应改为“for(i=j+1; in; i+)”;由后面的语句可知,要将位置p 和 j 的元素交换,变量 t 为中间变量,因此,“t=i;”应改为“p=i;”。三、程序设计题(总题数:1,分数:30.00)3.请编写一个函数 int proc(int*s,int t,int*k),用来求出数组的最大元素在数组中的下标并存放在k 所指的存储单元中。 例如,输入如下整数: 876 675 896 101 999 401 980 43

13、1 451 777 则输出结果为 4,999。 注意:部分源程序给出如下。 请勿改动 main()函数和其他函数中的任何内容,仅在函数 proc()的花括号中填入所编写的若干语句。 试题程序: #includestdlib.h #includeconio.h #includestdio.h int proc(int*s, int t, int*k) void main() int arr10=876, 675, 896, 101, 999, 401, 980, 431, 451, 777, k; system(“CLS“); proc(arr, 10, printf(“%d, %d/n“, k, arrk); (分数:30.00)_正确答案:()解析:int proc(int*s, int t, int*k) int i; *k=0; for(i=0; it; i+) /数组的最大元素在数组中的下标 if(s*ksi)*k=i; /将其放到 k 所指向的地址中 return s*k; /把最大值返回到主函数中 解析 要得到数组中的最大元素的下标,需要比较数组中的每一个元素。将最大的元素返回给主函数,最大元素的下标通过形参返回给主函数。

展开阅读全文
相关资源
猜你喜欢
  • ETSI TS 133 120-2001 Universal Mobile Telecommunications System (UMTS) 3G Security Security Principles and Objectives《全球移动通信系统(UMTS) 3G安全性 安全原则和目标 3G TS 33 120(版本4 0 0 第4次发布)》.pdf ETSI TS 133 120-2001 Universal Mobile Telecommunications System (UMTS) 3G Security Security Principles and Objectives《全球移动通信系统(UMTS) 3G安全性 安全原则和目标 3G TS 33 120(版本4 0 0 第4次发布)》.pdf
  • ETSI TS 133 141-2016 Universal Mobile Telecommunications System (UMTS) LTE Presence service Security (V13 0 0 3GPP TS 33 141 version 13 0 0 Release 13)《通用移动通信系统(UMTS) 长期演进技术(LTE) 在.pdf ETSI TS 133 141-2016 Universal Mobile Telecommunications System (UMTS) LTE Presence service Security (V13 0 0 3GPP TS 33 141 version 13 0 0 Release 13)《通用移动通信系统(UMTS) 长期演进技术(LTE) 在.pdf
  • ETSI TS 133 141-2017 Universal Mobile Telecommunications System (UMTS) LTE Presence service Security (V14 0 0 3GPP TS 33 141 version 14 0 0 Release 14)《通用移动通信系统(UMTS) 长期演进技术(LTE) 在.pdf ETSI TS 133 141-2017 Universal Mobile Telecommunications System (UMTS) LTE Presence service Security (V14 0 0 3GPP TS 33 141 version 14 0 0 Release 14)《通用移动通信系统(UMTS) 长期演进技术(LTE) 在.pdf
  • ETSI TS 133 141-2018 Universal Mobile Telecommunications System (UMTS) LTE Presence service Security (V15 0 0 3GPP TS 33 141 version 15 0 0 Release 15).pdf ETSI TS 133 141-2018 Universal Mobile Telecommunications System (UMTS) LTE Presence service Security (V15 0 0 3GPP TS 33 141 version 15 0 0 Release 15).pdf
  • ETSI TS 133 179-2016 LTE Security of Mission Critical Push To Talk (MCPTT) over LTE (V13 2 0 3GPP TS 33 179 version 13 2 0 Release 13)《长期演进技术(LTE) 长期演进技术(LTE) 在长期演进技术(LTE)上关键任务一键通(.pdf ETSI TS 133 179-2016 LTE Security of Mission Critical Push To Talk (MCPTT) over LTE (V13 2 0 3GPP TS 33 179 version 13 2 0 Release 13)《长期演进技术(LTE) 长期演进技术(LTE) 在长期演进技术(LTE)上关键任务一键通(.pdf
  • ETSI TS 133 179-2017 LTE Security of Mission Critical Push To Talk (MCPTT) over LTE (V13 4 0 3GPP TS 33 179 version 13 4 0 Release 13)《长期演进技术(LTE) 在长期演进技术上的关键任务一键通(MCPTT)的安全性(V13 4.pdf ETSI TS 133 179-2017 LTE Security of Mission Critical Push To Talk (MCPTT) over LTE (V13 4 0 3GPP TS 33 179 version 13 4 0 Release 13)《长期演进技术(LTE) 在长期演进技术上的关键任务一键通(MCPTT)的安全性(V13 4.pdf
  • ETSI TS 133 179-2018 LTE Security of Mission Critical Push To Talk (MCPTT) over LTE (V13 6 0 3GPP TS 33 179 version 13 6 0 Release 13).pdf ETSI TS 133 179-2018 LTE Security of Mission Critical Push To Talk (MCPTT) over LTE (V13 6 0 3GPP TS 33 179 version 13 6 0 Release 13).pdf
  • ETSI TS 133 180-2017 LTE Security of the mission critical service (V14 1 0 3GPP TS 33 180 version 14 1 0 Release 14).pdf ETSI TS 133 180-2017 LTE Security of the mission critical service (V14 1 0 3GPP TS 33 180 version 14 1 0 Release 14).pdf
  • ETSI TS 133 180-2018 LTE Security of the mission critical service (V15 2 0 3GPP TS 33 180 version 15 2 0 Release 15).pdf ETSI TS 133 180-2018 LTE Security of the mission critical service (V15 2 0 3GPP TS 33 180 version 15 2 0 Release 15).pdf
  • 相关搜索

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

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