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

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

1、二级 C 语言机试 300 及答案解析(总分:100.00,做题时间:90 分钟)一、B填空题/B(总题数:1,分数:30.00)1.请补充函数 fun(),该函数的功能是建立一个带头结点的单向链表并输出到文件“out98.dat”和屏幕上,各结点的值为对应的下标,链表的结点数及输出的文件名作为参数传入。注意:部分源程序给出如下。请勿改动主函数 main 和其他函数中的任何内容,仪在函数 fun()的横线上填入所编写的若干表达式或语句。试题程序:#includestdio. h#includeconio. h#includestdlib. htypedef struct ssint data;

2、struct ss *next; NODE;void fun(int n,char*filename)NODE *h,*p, *s;FILE *pf;int i;h=p= (NODE *) malloc (sizeof (NODE);h-data=0;for (i=1; is=(NODE *)malloc (sizeof (NODE);s-data=U 【1】 /U;U 【2】 /U;p=U 【3】 /Up-next=NULL;if ( (pf=fopen (filename, “w“) ) =NULL)printf “Can not open out9B.clat! “);exit (0);

3、p=h;fprintf (pf, “/n*THE LIST*/n“);print f (“/n*THE LIST*/n“)while (p)fprintf (pf, “%3d“, p-data)printf (“%3d“,p-data);if (p-next ! =NULL)fprintf (pf, “-“);printf (“-“);p=p-next;fprintf (pf, “/n“);printf (“/n“);fclose (pf);p=h;while (p) s=p;p=p-next;free (s);main()char * filename=“out98. dat“;int n;

4、clrscr ();printf (“ /nInput n: “);scanf (“%d“, fun (n, filename);(分数:30.00)填空项 1:_二、B改错题/B(总题数:1,分数:30.00)2.下列给定程序中,函数 fun()的功能是:计算 S=f(-n)+f(-n+1)+f(0)+f(1)+f(2)+f(n)的值。 例如,当 n 为 5 时,函数值应为 10.407143。f(x)函数定义如下: (分数:30.00)填空项 1:_三、B编程题/B(总题数:1,分数:40.00)3.请编写一个函数 void fun(cbara , charb , int n),其功能是:

5、删除一个字符申中指定下标的字符。其中,a 指向原字符串,删除后的字符串存放在 b 所指的数组中,n 中存放指定的下标。 例如,输入一个字符串 world,然后输入 3,则调用该函数后的结果为 word。 注意:部分源程序给出如下。 请勿改动主函数 main 和其他函数中的任何内容,仅在函数 fun 的花括号中填入所编写的若干语句。 试题程序: # include stdioh # include conioh # define LEN 20 void fun (char a, char b , int n) main () char str1 LEN, str2 LEN; int n ; cl

6、rscr (); printf (“Enter the string : /n“) ; gets (str1) ; printf (“Enter the position of the string deleted: “); scanf (“%d“, fun (str1, str2, n) ; printf (“The new string is : %s /n“, str2) ; (分数:40.00)_二级 C 语言机试 300 答案解析(总分:100.00,做题时间:90 分钟)一、B填空题/B(总题数:1,分数:30.00)1.请补充函数 fun(),该函数的功能是建立一个带头结点的单向

7、链表并输出到文件“out98.dat”和屏幕上,各结点的值为对应的下标,链表的结点数及输出的文件名作为参数传入。注意:部分源程序给出如下。请勿改动主函数 main 和其他函数中的任何内容,仪在函数 fun()的横线上填入所编写的若干表达式或语句。试题程序:#includestdio. h#includeconio. h#includestdlib. htypedef struct ssint data;struct ss *next; NODE;void fun(int n,char*filename)NODE *h,*p, *s;FILE *pf;int i;h=p= (NODE *) ma

8、lloc (sizeof (NODE);h-data=0;for (i=1; is=(NODE *)malloc (sizeof (NODE);s-data=U 【1】 /U;U 【2】 /U;p=U 【3】 /Up-next=NULL;if ( (pf=fopen (filename, “w“) ) =NULL)printf “Can not open out9B.clat! “);exit (0);p=h;fprintf (pf, “/n*THE LIST*/n“);print f (“/n*THE LIST*/n“)while (p)fprintf (pf, “%3d“, p-data)

9、printf (“%3d“,p-data);if (p-next ! =NULL)fprintf (pf, “-“);printf (“-“);p=p-next;fprintf (pf, “/n“);printf (“/n“);fclose (pf);p=h;while (p) s=p;p=p-next;free (s);main()char * filename=“out98. dat“;int n;clrscr ();printf (“ /nInput n: “);scanf (“%d“, fun (n, filename);(分数:30.00)填空项 1:_ (正确答案:1 i 2 p-

10、next=s 3 p-next)解析:解析 填空 1:题目要求各结点的值为对应的下标,头结点的值为 0,其他结点的值从 1 开始,所以此空应填 i。填空 2:为了将结点 p 和结点 s 连接起来,应将结点 p 的 next 指针指向结点 s。填空 3:为了通过 for 循环形成链表,每执行完一次循环操作,都要将指针 p 指向下一个结点。二、B改错题/B(总题数:1,分数:30.00)2.下列给定程序中,函数 fun()的功能是:计算 S=f(-n)+f(-n+1)+f(0)+f(1)+f(2)+f(n)的值。 例如,当 n 为 5 时,函数值应为 10.407143。f(x)函数定义如下: (

11、分数:30.00)填空项 1:_ (正确答案:错误;f(double x) 正确:double f (double x))解析:(2)错误;return s 正确:return s; 解析 该程序的流程是,fun()程序对 f (n)项循环累加,fun()程序采用条件选择语句计算函数 f(x)的值。本题错误在于未定义函数 f(double x)的返回值类型。C 语言规定,在未显式声明的情况下,函数返回值默认为 int 型。三、B编程题/B(总题数:1,分数:40.00)3.请编写一个函数 void fun(cbara , charb , int n),其功能是:删除一个字符申中指定下标的字符。

12、其中,a 指向原字符串,删除后的字符串存放在 b 所指的数组中,n 中存放指定的下标。 例如,输入一个字符串 world,然后输入 3,则调用该函数后的结果为 word。 注意:部分源程序给出如下。 请勿改动主函数 main 和其他函数中的任何内容,仅在函数 fun 的花括号中填入所编写的若干语句。 试题程序: # include stdioh # include conioh # define LEN 20 void fun (char a, char b , int n) main () char str1 LEN, str2 LEN; int n ; clrscr (); printf

13、Enter the string : /n“) ; gets (str1) ; printf (“Enter the position of the string deleted: “); scanf (“%d“, fun (str1, str2, n) ; printf (“The new string is : %s /n“, str2) ; (分数:40.00)_正确答案:()解析:void fun char a, char b,int n) int i,k=0; for(i=0;ai!=/0;i+) if (i!=n) /*将不是指定下标的字符存入数组 b 中*/ bk+=ai; bk=/0; /*在字符串最后加上结束标记*/ 解析 本题要求删除字符串中指定下标的字符,即相当于把不是指定下标的字符留下。所以要用 if(i!=n),注意不能写成“”运算。

展开阅读全文
相关资源
猜你喜欢
  • STAS 9976-1974 Plastics PBEPABATION OF SPECIMENS FOR OPTICAL TESTS Moulding method《塑料 光学试验用的标本的植被 成型方法 》.pdf STAS 9976-1974 Plastics PBEPABATION OF SPECIMENS FOR OPTICAL TESTS Moulding method《塑料 光学试验用的标本的植被 成型方法 》.pdf
  • STAS 9977 1-1975 VULCANIZED RUBBERS Determination of compression set under constant deflectionat low temperatures《硫化橡胶 在恒定偏转低温下测定压力定形 》.pdf STAS 9977 1-1975 VULCANIZED RUBBERS Determination of compression set under constant deflectionat low temperatures《硫化橡胶 在恒定偏转低温下测定压力定形 》.pdf
  • STAS 9978-1985 Leathers for technical goods LEATHERS FOR BRAKECYLIN- DER L1NINGSFOR RA1LMAY VEHICLES 《技术商品用的皮革 用于铁路车辆制动缸衬层的皮革 》.pdf STAS 9978-1985 Leathers for technical goods LEATHERS FOR BRAKECYLIN- DER L1NINGSFOR RA1LMAY VEHICLES 《技术商品用的皮革 用于铁路车辆制动缸衬层的皮革 》.pdf
  • STAS 9979 1-1974 INDOOR BUSHINGS WITH OUTER METAL FITTINGS FOR 6 AND 10 kV GLASS C Insulators with fittings《6 和 10 千伏的具有外部小五金的室内套管,C级,带配件的绝缘子 》.pdf STAS 9979 1-1974 INDOOR BUSHINGS WITH OUTER METAL FITTINGS FOR 6 AND 10 kV GLASS C Insulators with fittings《6 和 10 千伏的具有外部小五金的室内套管,C级,带配件的绝缘子 》.pdf
  • STAS 9979 2-1974 INDOOR BUSHINGS WITH OUTER METAL FITTINGS FOR 6 AND 10 kV GLASS G Insulators without fittings Dimcnsions《6 和 10 千伏的具有外部小五金的室内套管,G级,无配件的绝缘子尺寸 》.pdf STAS 9979 2-1974 INDOOR BUSHINGS WITH OUTER METAL FITTINGS FOR 6 AND 10 kV GLASS G Insulators without fittings Dimcnsions《6 和 10 千伏的具有外部小五金的室内套管,G级,无配件的绝缘子尺寸 》.pdf
  • STAS 9979 3-1990 Indoor bushings with outer metal fitting of 7 2 and 12 kV stress class 12 5 kN FITTINGS Dimensions《外部有金属零件的室内绝缘衬套,7,2 和 12 千伏,压力级12 5千牛,配件尺寸 》.pdf STAS 9979 3-1990 Indoor bushings with outer metal fitting of 7 2 and 12 kV stress class 12 5 kN FITTINGS Dimensions《外部有金属零件的室内绝缘衬套,7,2 和 12 千伏,压力级12 5千牛,配件尺寸 》.pdf
  • STAS 9980 1-1989 Assembly tools for screws and nuts Open end slugging wrench Dimensions《螺丝和螺母用的装配工具 开放式打扳手尺寸 》.pdf STAS 9980 1-1989 Assembly tools for screws and nuts Open end slugging wrench Dimensions《螺丝和螺母用的装配工具 开放式打扳手尺寸 》.pdf
  • STAS 9980 2-1989 Assembly tools for screws and nuts BOX RING SLUGGING WRENCH Dimcnsions《螺丝和螺母的装配工具,盒环打扳手尺寸 》.pdf STAS 9980 2-1989 Assembly tools for screws and nuts BOX RING SLUGGING WRENCH Dimcnsions《螺丝和螺母的装配工具,盒环打扳手尺寸 》.pdf
  • STAS 9981-1982 BASIC SYMBOL FOR IONIZING RADIATIONS《电离辐射的基本符号 》.pdf STAS 9981-1982 BASIC SYMBOL FOR IONIZING RADIATIONS《电离辐射的基本符号 》.pdf
  • 相关搜索

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

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