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

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

1、二级 C语言机试-206 及答案解析(总分:100.00,做题时间:90 分钟)一、填空题(总题数:1,分数:30.00)1.请补充 main函数,该函数的功能是:输出一个 33的矩阵,要求必须使用行指针表示输出变量。注意;部分源程序给出如下请勿改动主函数 main和其他函数中的任何内容,仅在 main 函数的横线上填入所编写的若干表达式或语句。试题程序:#includes tdio. hmain()static int array3 3=9,8,7, 6,5,4, (3,2,1;iht (*p) 3,j,i;p=【1】clrscr ();for (i=0; i3; i+)printf (“

2、/n/n“ );for (j=0; j3; j+)printf(“%4d“, 【2】 );(分数:30.00)填空项 1:_二、改错题(总题数:1,分数:30.00)2.下列给定程序中,函数 fun()的功能是:计算整数 n的阶乘。请改正程序中的错误,使它能得出正确的结果。注意:不要改动 main函数,不得增行或删行,也不得更改程序的结构。试题程序:#include stdio.hdouble fun(int n)double result=l.0;whil (nl/*found*/return;main()int. n;clrscr();printf(“Enter an integer: “

3、);scanf(“%d“,printf(“/n/n%d!=%lg/n/n “,n, fun(n);(分数:30.00)填空项 1:_三、编程题(总题数:1,分数:40.00)3.N名学生的成绩己在主函数中放入一个带头节点的链表结构中,h 指向链表的头节点。请编写函数 fun(),它的功能是:求出平均分,由函数值返回。例如,若学生的成绩是 85,76,69,91,72,64,87,则平均分应当是 78.625。注童:部分源程序给出如下请勿改动主函数 main和其他函数中的任何内容,仅在函数 6m的花括号中填入所编写的若干语句。试题程序:#includestdlib.h#includestdio.

4、 h#define N 8struct slistdouble s;struct slist *next;typedef struct slist STREC;double fun(STREC *h)STREC *creat(double *s) /*创建链表*/STREC *h,*p, *q;int i=0;h=p= ( STREC*)malloc (sizeof (STREC);p-s=0;while (iN)q= ( STREC*)malloc (sizeof (STREC);q-s=s Ii; i+;p-next=q;p=q;p-next=0;return h;outlist (STR

5、EC *h)STREC *p;p=h-next;printf (“head “);doprintf (“-%4. if “,p-s);p=p-next; /*输出各成绩*/while (p !=0)main ()double s N = 85,76, 69, 85, 91,72, 64,87,ave;STREC *h;h=creat (s);outlist (h);ave=fun (h);printf (“ave=%6.3f/n “, ave);(分数:40.00)_二级 C语言机试-206 答案解析(总分:100.00,做题时间:90 分钟)一、填空题(总题数:1,分数:30.00)1.请补

6、充 main函数,该函数的功能是:输出一个 33的矩阵,要求必须使用行指针表示输出变量。注意;部分源程序给出如下请勿改动主函数 main和其他函数中的任何内容,仅在 main 函数的横线上填入所编写的若干表达式或语句。试题程序:#includes tdio. hmain()static int array3 3=9,8,7, 6,5,4, (3,2,1;iht (*p) 3,j,i;p=【1】clrscr ();for (i=0; i3; i+)printf (“ /n/n“ );for (j=0; j3; j+)printf(“%4d“, 【2】 );(分数:30.00)填空项 1:_ (正

7、确答案:1array 2*(*(p+i)+j))解析:解析 填空 1:p 是一个指针,指向大小为 3的一维数组。首先要使指针 p指向数组 array的首地址,而数组名 array即表示数组 slray的首地址,所以将 array赋给 p。填空 2:*(*(p+i+j)表示数组的第 i行第 j列元素,即 arrayij。二、改错题(总题数:1,分数:30.00)2.下列给定程序中,函数 fun()的功能是:计算整数 n的阶乘。请改正程序中的错误,使它能得出正确的结果。注意:不要改动 main函数,不得增行或删行,也不得更改程序的结构。试题程序:#include stdio.hdouble fun

8、int n)double result=l.0;whil (nl/*found*/return;main()int. n;clrscr();printf(“Enter an integer: “);scanf(“%d“,printf(“/n/n%d!=%lg/n/n “,n, fun(n);(分数:30.00)填空项 1:_ (正确答案:(1)错误:result*=-n; 正确:result*=n-;(2)错误:return; 正确:return result;)解析:解析 该题采用循环语句计算 n的阶乘。当 n大于 1且小于 170时,令 result与 n相乘,同时 n自动减 1,循环至

9、 n=2(n=1时无需相乘):注意:o 和 1的阶乘都等于 1,可用条件语句和循环语句实现上述功能。三、编程题(总题数:1,分数:40.00)3.N名学生的成绩己在主函数中放入一个带头节点的链表结构中,h 指向链表的头节点。请编写函数 fun(),它的功能是:求出平均分,由函数值返回。例如,若学生的成绩是 85,76,69,91,72,64,87,则平均分应当是 78.625。注童:部分源程序给出如下请勿改动主函数 main和其他函数中的任何内容,仅在函数 6m的花括号中填入所编写的若干语句。试题程序:#includestdlib.h#includestdio. h#define N 8str

10、uct slistdouble s;struct slist *next;typedef struct slist STREC;double fun(STREC *h)STREC *creat(double *s) /*创建链表*/STREC *h,*p, *q;int i=0;h=p= ( STREC*)malloc (sizeof (STREC);p-s=0;while (iN)q= ( STREC*)malloc (sizeof (STREC);q-s=s Ii; i+;p-next=q;p=q;p-next=0;return h;outlist (STREC *h)STREC *p;p

11、h-next;printf (“head “);doprintf (“-%4. if “,p-s);p=p-next; /*输出各成绩*/while (p !=0)main ()double s N = 85,76, 69, 85, 91,72, 64,87,ave;STREC *h;h=creat (s);outlist (h);ave=fun (h);printf (“ave=%6.3f/n “, ave);(分数:40.00)_正确答案:(double fun(STREC *h)double av=0.0;STREC *p-h-next; /*p直接指向“头结点”的下一个结点,即第个成绩*/while(p!=NULL)aY=ay+p-s; /*求总分数*/p=p-next;return ay/N; /*返回平均值*/)解析:解析 本题是关于链表问题,所以,一定要弄清表示出使指针变量 p指向下一个“结点”的方法及表示结束的判断,本题中,因为“头结点”中没有数值,所以程序中让 p直接指向“头结点”的下一个结点,使用语句 STREC*p=h-next,当然也可将 p一开始就指向“头结点”。

展开阅读全文
相关资源
猜你喜欢
  • DIN EN 3777-2011 Aerospace series - Pins quick release single and double acting - Technical specification German and English version EN 3777 2010《航空航天系列 插脚 快拆杆 单动和复动 技术规范 德文版本和英文版本.pdf DIN EN 3777-2011 Aerospace series - Pins quick release single and double acting - Technical specification German and English version EN 3777 2010《航空航天系列 插脚 快拆杆 单动和复动 技术规范 德文版本和英文版本.pdf
  • DIN EN 378-3-2017 Refrigerating systems and heat pumps - Safety and environmental requirements - Part 3 Installation site and personal protection German version EN 378-3 2016《制冷系统和.pdf DIN EN 378-3-2017 Refrigerating systems and heat pumps - Safety and environmental requirements - Part 3 Installation site and personal protection German version EN 378-3 2016《制冷系统和.pdf
  • DIN EN 378-4-2017 Refrigerating systems and heat pumps - Safety and environmental requirements - Part 4 Operation maintenance repair and recovery German version EN 378-4 2016《制冷系统和.pdf DIN EN 378-4-2017 Refrigerating systems and heat pumps - Safety and environmental requirements - Part 4 Operation maintenance repair and recovery German version EN 378-4 2016《制冷系统和.pdf
  • DIN EN 3781-2008 Aerospace series - Grooves for spiral wound retaining rings - Design standard German and English version EN 3781 2008《航空航天系列 弹簧绕制固定环用槽 设计标准》.pdf DIN EN 3781-2008 Aerospace series - Grooves for spiral wound retaining rings - Design standard German and English version EN 3781 2008《航空航天系列 弹簧绕制固定环用槽 设计标准》.pdf
  • DIN EN 3782-2008 Aerospace series - Holes for 100 countersunk head screws - Design standard German and English version EN 3782 2008《航空航天系列 100埋头螺钉用孔 设计标准》.pdf DIN EN 3782-2008 Aerospace series - Holes for 100 countersunk head screws - Design standard German and English version EN 3782 2008《航空航天系列 100埋头螺钉用孔 设计标准》.pdf
  • DIN EN 3783-2013 Aerospace series - Fibre composite materials - Normalization of fibre dominated mechanical properties German and English version EN 3783 2013《航空航天系列 纤维复合材料 纤维为主的力学.pdf DIN EN 3783-2013 Aerospace series - Fibre composite materials - Normalization of fibre dominated mechanical properties German and English version EN 3783 2013《航空航天系列 纤维复合材料 纤维为主的力学.pdf
  • DIN EN 3788-2004 Aerospace series - Pipe coupling 830 - Protective caps German and English version EN 3788 2001 + AC 2003《航空航天系列 管连接件830- 防护管帽》.pdf DIN EN 3788-2004 Aerospace series - Pipe coupling 830 - Protective caps German and English version EN 3788 2001 + AC 2003《航空航天系列 管连接件830- 防护管帽》.pdf
  • DIN EN 3789-2004 Aerospace series - Pipe coupling 830 - Protective plugs with external threads German and English version EN 3789 2001 + AC 2003《航空航天系列 管连接件830- 带外螺纹的防护管塞》.pdf DIN EN 3789-2004 Aerospace series - Pipe coupling 830 - Protective plugs with external threads German and English version EN 3789 2001 + AC 2003《航空航天系列 管连接件830- 带外螺纹的防护管塞》.pdf
  • DIN EN 379-2009 Personal eye-protection - Automatic welding filters (includes Amendment A1 2009) English version of DIN EN 379 2009-07《个人眼护设备 自动焊接滤光镜(包括修改件A1 2009) DIN EN 379 2009-.pdf DIN EN 379-2009 Personal eye-protection - Automatic welding filters (includes Amendment A1 2009) English version of DIN EN 379 2009-07《个人眼护设备 自动焊接滤光镜(包括修改件A1 2009) DIN EN 379 2009-.pdf
  • 相关搜索

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

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