[计算机类试卷]国家二级(C语言)机试模拟试卷349及答案与解析.doc

上传人:lawfemale396 文档编号:503107 上传时间:2018-11-29 格式:DOC 页数:5 大小:129.50KB
下载 相关 举报
[计算机类试卷]国家二级(C语言)机试模拟试卷349及答案与解析.doc_第1页
第1页 / 共5页
[计算机类试卷]国家二级(C语言)机试模拟试卷349及答案与解析.doc_第2页
第2页 / 共5页
[计算机类试卷]国家二级(C语言)机试模拟试卷349及答案与解析.doc_第3页
第3页 / 共5页
[计算机类试卷]国家二级(C语言)机试模拟试卷349及答案与解析.doc_第4页
第4页 / 共5页
[计算机类试卷]国家二级(C语言)机试模拟试卷349及答案与解析.doc_第5页
第5页 / 共5页
亲,该文档总共5页,全部预览完了,如果喜欢就下载吧!
资源描述

1、国家二级( C语言)机试模拟试卷 349及答案与解析 一、程序填空题( 30分) 1 二、程序修改题( 30分) 2 给定程序 MODll C中函数 fun的功能是:实现两个整数的交换。 例如给 a和 b分别输入: 60和 65,输出为: a=65 b=60 请改正程序中的错误,使它能得出正确的结果。 注意:不要改动 main函数,不得增行或删行,也不得更改程序的结构 ! #include /*found*/ void fun(int a, b) int t; /*found*/ t=b; b=a; a=t; main () int a, b; printf (“Enter a , b : “

2、); scanf (“%d,%d“, fun ( printf (“ a = %d b = %dn “, a, b); 三、程序设计题( 40分) 3 编写函数 fun,函数的功能是:从 s所指的字符串中删除给定的字符。同一字母的大、小写按不同字符处理。 若程序执行时输入字符串为: turbo c andborlaM c+ 从键盘上输入字符: n,则输出后变为: turbo c ad borlad C+ 如果输入的字符在字符串中不存在,则字符串照原样输出。 注意:部分源程序在文件 PROGl C中。 请勿改动主函数 main和其他函数中的任何内容,仅在函数 fun的花括号中填入你编写的若干语句

3、 #include #include void fun(char s,char c) si=0; NONO() /* 请在此函数内打开文件,输入测试数据,调用 fun 函数,输出数据,关闭文件。 */ FILE *rf, *wf ; char s81, ch, w ; int len ; rf = fopen(“in.dat“,“r“); wf = fopen(“out.dat“,“w“); fgets(s, 80, rf); fscanf(rf, “%c“, len = strlen(s) - 1 ; w = slen ; if(w = n | w = 0x1a) slen = 0 ; f

4、un(s, ch); fprintf(wf, “%s“, s); fclose(rf); fclose(wf); main() static char str=“turbo c and borland c+“; char ch; printf(“原始字符串 :%sn“, str); printf(“输入一个字符 :“); scanf(“%c“, fun(str,ch); printf(“str=%sn“,str); NONO(); 国家二级( C语言)机试模拟试卷 349答案与解析 一、程序填空题( 30分) 1 【正确答案】 sum=0 tii 1 【试题解析】 第一空:由 “return

5、sum;”可知 sum变量记录了主对角线元素和反向对角线元素之和,第一空处是在使用 sum变量之前对其初始化,因此第一空处应为 “sum=0;” 第二空:由第二个循环内 “sum+=tin-i-_3_;”可知,第一个循环是主对角元素和,第二个循环求反向对角线元素之和,因此第二空处应为 “tii”。 第三空:第二个循环求反向对角线元素之和,反向对角元素为 tin-i-1,故第三空应为 “1”。 二、程序修改题( 30分) 2 【正确答案】 void fun(int *a,int *b) t=*b; *b=*a; *a=t; 【试题解析】 ( 1)该题明显是指针类型的错误。主函数传的形参分别是 a

6、 b的地址,而函数 fun中却定义 a、 b为整型,所以第一个标识下的 “void fun(int a, b)”改为 “void fun(int *a,int *b)”。 ( 2)根据上面的修改,第二个标识下, “t=b; b=a; a=t;”明显应该是 “t=*b; *b=*a; *a=t;”。 三、程序设计题( 40分) 3 【正确答案】 char *p=s; int i=0; while(*p) if(*p !=c)si+=*p; p+; 【试题解析】 进入 fun函数,根据前面的分析: ( 1)首先,设置一个指针变量指向字符串的头位置,并使用循环,依次查找字符串中 的指定字符。 ( 2)若找到指定字符,则将后面位置的第一个非指定字符移到当前位置,并将其后的字符也依次前移。 ( 3)最后将处理的字符串输出。

展开阅读全文
相关资源
猜你喜欢
  • ANSI ISO IEC 11694-2-2000 Identification cards Optical memory cards Linear recording method Part 2 Dimensions and location of the accessible optical area (Adopted by INCITS)《识别卡.光学.pdf ANSI ISO IEC 11694-2-2000 Identification cards Optical memory cards Linear recording method Part 2 Dimensions and location of the accessible optical area (Adopted by INCITS)《识别卡.光学.pdf
  • ANSI ISO IEC 11694-3-2001 Identification cards Optical memory cards Linear recording method Part 3 Optical properties and characteristics (Adopted by INCITS)《识别卡.光学存储卡.线性记录方法.第3部分 .pdf ANSI ISO IEC 11694-3-2001 Identification cards Optical memory cards Linear recording method Part 3 Optical properties and characteristics (Adopted by INCITS)《识别卡.光学存储卡.线性记录方法.第3部分 .pdf
  • ANSI ISO IEC 11694-4-2001 Identification cards Optical memory cards Linear recording method Part 4 Logical data structures (Adopted by INCITS)《识别卡.光学存储卡.线性记录方法.第4部分 被INCITS采用的逻辑数据结.pdf ANSI ISO IEC 11694-4-2001 Identification cards Optical memory cards Linear recording method Part 4 Logical data structures (Adopted by INCITS)《识别卡.光学存储卡.线性记录方法.第4部分 被INCITS采用的逻辑数据结.pdf
  • ANSI ISO IEC 11730-1994 Information Technology - Programming Languages - Form Interface Management System (Adopted by INCITS)《信息技术.程序设计语言.INCITS采纳的表单界面管理系统》.pdf ANSI ISO IEC 11730-1994 Information Technology - Programming Languages - Form Interface Management System (Adopted by INCITS)《信息技术.程序设计语言.INCITS采纳的表单界面管理系统》.pdf
  • ANSI ISO IEC 12087-1-1995 Information Technology Computer Graphics and Image Processing Image Processing and Interchange (IPI) Functional Specification Part 1 Common Architecture f.pdf ANSI ISO IEC 12087-1-1995 Information Technology Computer Graphics and Image Processing Image Processing and Interchange (IPI) Functional Specification Part 1 Common Architecture f.pdf
  • ANSI ISO IEC 12088-4-1995 Information Technology – Computer Graphics and Image Processing – Image Processing and Interchange – Application Program Interface Language Bindings – P.pdf ANSI ISO IEC 12088-4-1995 Information Technology – Computer Graphics and Image Processing – Image Processing and Interchange – Application Program Interface Language Bindings – P.pdf
  • ANSI ISO IEC 12089-1997 Information technology - Computer graphics and image processing - Encoding for the Image Interchange Facility (IIF) (Adopted by INCITS)《信息技术.计算机图形和图像处理.INCI.pdf ANSI ISO IEC 12089-1997 Information technology - Computer graphics and image processing - Encoding for the Image Interchange Facility (IIF) (Adopted by INCITS)《信息技术.计算机图形和图像处理.INCI.pdf
  • ANSI ISO IEC 12246-1993 Information technology - 8 mm wide magnetic tape cartridge dual azimuth format for information interchange - Helical scan recording (Adopted by INCITS)《信息技术.pdf ANSI ISO IEC 12246-1993 Information technology - 8 mm wide magnetic tape cartridge dual azimuth format for information interchange - Helical scan recording (Adopted by INCITS)《信息技术.pdf
  • ANSI ISO IEC 13249-3-1999 Information technology Database languages SQL multimedia and application packages Part 3 Spatial (Adopted by INCITS)《信息技术.数据库语言SQL.SQL多媒体和应用程序包.第3部分 被INCI.pdf ANSI ISO IEC 13249-3-1999 Information technology Database languages SQL multimedia and application packages Part 3 Spatial (Adopted by INCITS)《信息技术.数据库语言SQL.SQL多媒体和应用程序包.第3部分 被INCI.pdf
  • 相关搜索

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

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