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

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

1、国家二级 C语言机试(操作题)模拟试卷 544及答案与解析 一、程序填空题 1 给定程序中,函数 fhn的功能是:判断形参 s所指字符串是否是 “回文“(Palindrome),若是,函数返回值为 1;不是,函数返回值为 0。 “回文 “是正读和反读都一样的字符串 (不区分大小写字母 )。 例如, LEVEL和 Level是 ”回文 ”,而 LEVLEV不是 ”回文 ”。 请在程序的下画线处填入正确的内容并把下画线删除,使程序得出正确的结果。 注意:部分源程序在文件 BLANK1 C中。 不得增行或删行,也不得 更改程序的结构 ! 试题程序: #include stdio h #include

2、 string h #include ctype h int fun(char*s) char*lp, *rp; *found* lp=【 1】 ; rp=s+strlen(s)一 1; while(toupper(*lp)=toupper (*rp)&(ip rp) *found* lp+; rp【 2】 ; *found* if(ip rp) 【 3】 ; else return 1; main() char s81; printf(“Enter a string: “); scanf(“ s“, s); if(fun(s) printf(“ n “ s “is a Pal indrome

3、 n n“, s); else printf(“ n “ s “isnt a palindrome n n“, s); 二、程序修改题 2 下列给定程序中,函数 fun的功能是:求出如下分数列的前 n项之和。和值通过函数值返回 main函数。例如,若 n: 5,则应输出 8 391667。 请改正程序中的错误,使它能得出正确的结果。 注意:部分源程序在文件 MODll C中,不要改动 main函数,不得增行或删行,也不得更改程序的结构 ! 试题程序: #include stdlib h #include conio h #include stdio h *found* fun(int n)in

4、t a, b, c, k; double s; s=0 0;a=2; b=1; for(k=1; k =n; k+) *found* s=s+(Double)a b; c=a; a=a+b; b=c; return s; main()int n=5; system(“CLS“); printf(“nThe value of function is: lf n“, fun(n); 三、程序设计题 3 请编写一个函数 void fun(int m, intk, int xx),该函数的功能是:将大于整数 m且紧靠 m的 k个素数存入所指的数组中。 例如,若输入 17, 5,则应输出 19、 23、

5、 29、 31、 37。 注意:部分源程序在文件 PROGl C中。 请勿改动主函数 main和其他函数中的任何内容,仅在函数 fun的花括号中填入你编写的若干语句。 试题程序: #include conio h #include stdio h #include Stdlib h void fun(int m, int k, int xx) void main() FILE*wf; int m, n, zz1000; system(“CLS“); printf(“ nPlease enter two in tegers: “); scanf(“ d d“, &m, &n); fun(m, n

6、, zz); for(m=0; m n; m+) printf(“ d“, zzm); printf(“ n“); * wf=fopen(“out dat“, “w“); fun(17, 5, zz); for(m=0; m 5; m+) fprintf(wf, “ d“, zzm); fclose(wf); * 国家二级 C语言机试(操作题)模拟试卷 544答案与解析 一、程序填空题 1 【正确答案】 (1)s (2)- (3)return 0 【试题解析】 填空 1:根据函数体 fun中,对变量 lp和 rp的使用可知, lp应指向形参 s的起始地址, rp指向 s的结尾地址,所以应填 s

7、。 填空 2: rp是指向字符串的尾指针,当每做一次循环 rp向前移动一个位置,所以应填: -。 填空 3:当 lp和 rp相等时,表示字符串是回文并返回 1,否则就返回 0,所以应填 return 0。 二、程序修改题 2 【正确答案】 (1)double fun(int n) (2)s=s+(double)a/b; 【试题解析】 (1)由于返回值 s是 double型的,所以函数要定义为 double型。 (2)C语言规定所有关键字都必须用小写英文字母表示,所以 s=s+(Double)a b;应改为 s=s+ (double)a b;。 三、程序设计题 3 【正确 答案】 void fun(int m, int k, int xx) int i, j, n; for(i=m+1, n=0; n k; i+) * 找大于 m的素数,循环 k次,即找出紧靠 m的 k个素数 * for(j=2; j i; j+) *判断 个数是否为素数,如果不是,跳出此循环,判断下一个数 * if(i j=0)break; if(j =i) *如果是素数,放入数组 xx中 * xxn+=i; 【试题解析】 本题主要考查素数的判定方法,如果一个数不能被除了 1和其自身以外的数整 除,则这个数为素数。本程序使用循环语句控制需要判断的数,在循环体中判断该数是否为素数,若是则存入数组 xx中。

展开阅读全文
相关资源
猜你喜欢
  • ASTM A1044 A1044M-2005(2010) Standard Specification for Steel Stud Assemblies for Shear Reinforcement of Concrete《混凝土抗剪钢筋用钢螺柱组件的标准规格》.pdf ASTM A1044 A1044M-2005(2010) Standard Specification for Steel Stud Assemblies for Shear Reinforcement of Concrete《混凝土抗剪钢筋用钢螺柱组件的标准规格》.pdf
  • ASTM A1044 A1044M-2015 Standard Specification for Steel Stud Assemblies for Shear Reinforcement of Concrete《混凝土抗剪钢筋用钢螺柱总成的标准规格》.pdf ASTM A1044 A1044M-2015 Standard Specification for Steel Stud Assemblies for Shear Reinforcement of Concrete《混凝土抗剪钢筋用钢螺柱总成的标准规格》.pdf
  • ASTM A1044 A1044M-2016 Standard Specification for Steel Stud Assemblies for Shear Reinforcement of Concrete《混凝土抗剪钢筋用钢螺柱总成的标准规格》.pdf ASTM A1044 A1044M-2016 Standard Specification for Steel Stud Assemblies for Shear Reinforcement of Concrete《混凝土抗剪钢筋用钢螺柱总成的标准规格》.pdf
  • ASTM A1044 A1044M-2016a Standard Specification for Steel Stud Assemblies for Shear Reinforcement of Concrete《混凝土剪切钢筋用钢柱组件的标准规格》.pdf ASTM A1044 A1044M-2016a Standard Specification for Steel Stud Assemblies for Shear Reinforcement of Concrete《混凝土剪切钢筋用钢柱组件的标准规格》.pdf
  • ASTM A1045-2005 Standard Specification for Flexible Poly (Vinyl Chloride) (PVC) Gaskets used in Connection of Water Closets to Sanitary Drainage System《抽水马桶与卫生排水系统连接用柔性聚氯乙烯(PVC)垫圈的.pdf ASTM A1045-2005 Standard Specification for Flexible Poly (Vinyl Chloride) (PVC) Gaskets used in Connection of Water Closets to Sanitary Drainage System《抽水马桶与卫生排水系统连接用柔性聚氯乙烯(PVC)垫圈的.pdf
  • ASTM A1045-2008 Standard Specification for Flexible Poly (Vinyl Chloride) (PVC) Gaskets used in Connection of Water Closets to Sanitary Drainage System《抽水马桶与卫生排水系统连接用柔性聚氯乙烯(PVC)垫圈的.pdf ASTM A1045-2008 Standard Specification for Flexible Poly (Vinyl Chloride) (PVC) Gaskets used in Connection of Water Closets to Sanitary Drainage System《抽水马桶与卫生排水系统连接用柔性聚氯乙烯(PVC)垫圈的.pdf
  • ASTM A1045-2010 Standard Specification for Flexible Poly (Vinyl Chloride) (PVC) Gaskets used in Connection of Vitreous China Plumbing Fixtures to Sanitary Drainage Systems《抽水马桶与卫生排.pdf ASTM A1045-2010 Standard Specification for Flexible Poly (Vinyl Chloride) (PVC) Gaskets used in Connection of Vitreous China Plumbing Fixtures to Sanitary Drainage Systems《抽水马桶与卫生排.pdf
  • ASTM A1045-2010(2014) Standard Specification for Flexible Poly &40 Vinyl Chloride&41 &40 PVC&41 Gaskets used in Connection of Vitreous China Plumbing Fixtures to Sanitary Drainage .pdf ASTM A1045-2010(2014) Standard Specification for Flexible Poly &40 Vinyl Chloride&41 &40 PVC&41 Gaskets used in Connection of Vitreous China Plumbing Fixtures to Sanitary Drainage .pdf
  • ASTM A1045-2010(2017) Standard Specification for Flexible Poly (Vinyl Chloride) (PVC) Gaskets used in Connection of Vitreous China Plumbing Fixtures to Sanitary Drainage Systems《抽水.pdf ASTM A1045-2010(2017) Standard Specification for Flexible Poly (Vinyl Chloride) (PVC) Gaskets used in Connection of Vitreous China Plumbing Fixtures to Sanitary Drainage Systems《抽水.pdf
  • 相关搜索

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

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