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

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

1、二级 C 语言-335 及答案解析(总分:100.00,做题时间:90 分钟)一、程序填空题(总题数:1,分数:30.00)1.甲、乙、丙、丁 4 人同时开始放鞭炮,甲每隔 t1 秒放一次,乙每隔 t2 秒放一次,丙每隔 t3 秒放一次,丁每隔 t4 秒放一次,每人各放 n 次。函数 fun 的功能是根据形参炸响,只算一次响声,第一次响声是在第 0 秒。 例如,若 t1=7,t2=5,t3=6,t4=4,n=10,则总共可听到 28 次鞭炮声。 请在程序的下划线处填入正确的内容并把下划线删除,使程序得出正确的结果。 注意:部分源程序给出如下。 不得增行或删行,也不得更改程序的结构! 试题程序:

2、 #includestdio.h /*found*/ #define OK(i, t, n( 1%t=0) if(maxtt2)maxt=t2; if(maxtt3)maxt=t3; if(maxtt4)maxt=t4; count=1; /*给 count 赋初值*/ /*found*/ for(t=1; tmaxt*(n-1); 2) if(OK(t, t1, n)|OK(t, t2, n)|OK(t, t3, n)|OK(t, t4, n) count+; /*found*/ return 3; main() int t1=7, t2=5, t3=6, t4=4, n=10, r; r=

3、fun(t1, t2, t3, t4, n); printf(“The sound:%d/n“, r); (分数:30.00)二、程序改错题(总题数:1,分数:30.00)2.下列给定程序中,函数 fun 的功能是:根据输入的三个边长(整型值),判断能否构成三角形。若能构成等边三角形,则返回 3;若是等腰三角形,则返回 2;若能构成三角形,则返回 1;若不能,则返回 0。 请改正程序中的错误,使它能得出正确的结果。 注意:不要改动 main 函数,不得增行或删行,也不得更改程序的结构! 试题程序: #includestdio.h #includemath.h int fun(int a, in

4、t b, int c) if(a+bc else if(a=b|b=c|a=c) return 2; /*found*/ else return 3; else return 0; void main() int a, b, c, shape; printf(“/nlnput a, b, c:“); scanf(“%d%d%d“, printf(“/na=%d, b=%d, c=%d/n“, a, b, c); shape=fun(a, b, c); printf(“/n/nThe shape:%d/n“, shape); (分数:30.00)三、程序设计题(总题数:1,分数:40.00)3.

5、请编写函数 fun,其功能是:计算并输出 3n 所有素数的平方根之和。 例如,若主函数从键盘给 n 输入 100 后,则输出为 sum=148874270。 注意:n 的值要大于 2 但不大于 100。部分源程序给出如下。 请勿改动主函数 main 和其他函数中的任何内容,仅在函数 fun 的花括号中填入你编写的若干语句。 试题程序: #includemath.h #includestdio.h double fun(int n) main() int n; double sum; printf(“/n/nInput n:“); scanf(“%d“, sum=fun(n); printf(“

6、/n/nsum=%f/n/n“, sum); (分数:40.00)_二级 C 语言-335 答案解析(总分:100.00,做题时间:90 分钟)一、程序填空题(总题数:1,分数:30.00)1.甲、乙、丙、丁 4 人同时开始放鞭炮,甲每隔 t1 秒放一次,乙每隔 t2 秒放一次,丙每隔 t3 秒放一次,丁每隔 t4 秒放一次,每人各放 n 次。函数 fun 的功能是根据形参炸响,只算一次响声,第一次响声是在第 0 秒。 例如,若 t1=7,t2=5,t3=6,t4=4,n=10,则总共可听到 28 次鞭炮声。 请在程序的下划线处填入正确的内容并把下划线删除,使程序得出正确的结果。 注意:部分源

7、程序给出如下。 不得增行或删行,也不得更改程序的结构! 试题程序: #includestdio.h /*found*/ #define OK(i, t, n( 1%t=0) if(maxtt2)maxt=t2; if(maxtt3)maxt=t3; if(maxtt4)maxt=t4; count=1; /*给 count 赋初值*/ /*found*/ for(t=1; tmaxt*(n-1); 2) if(OK(t, t1, n)|OK(t, t2, n)|OK(t, t3, n)|OK(t, t4, n) count+; /*found*/ return 3; main() int t1

8、7, t2=5, t3=6, t4=4, n=10, r; r=fun(t1, t2, t3, t4, n); printf(“The sound:%d/n“, r); (分数:30.00)解析:(1)i (2)t+ (3)count 解析 填空 1:在 OK 函数里 i 应该代表的是放鞭炮的次数,因而在第一空应该填 i。 填空 2:在 OK 函数里 t 代表的是间隔的秒数,for 循环中的此空该填 t+。 填空 3:最后返回的应该是听到的鞭炮总共的炸响声,本题中 count 代表的是鞭炮总共的炸响声,因而此空应填 count。二、程序改错题(总题数:1,分数:30.00)2.下列给定程序中

9、函数 fun 的功能是:根据输入的三个边长(整型值),判断能否构成三角形。若能构成等边三角形,则返回 3;若是等腰三角形,则返回 2;若能构成三角形,则返回 1;若不能,则返回 0。 请改正程序中的错误,使它能得出正确的结果。 注意:不要改动 main 函数,不得增行或删行,也不得更改程序的结构! 试题程序: #includestdio.h #includemath.h int fun(int a, int b, int c) if(a+bc else if(a=b|b=c|a=c) return 2; /*found*/ else return 3; else return 0; void

10、 main() int a, b, c, shape; printf(“/nlnput a, b, c:“); scanf(“%d%d%d“, printf(“/na=%d, b=%d, c=%d/n“, a, b, c); shape=fun(a, b, c); printf(“/n/nThe shape:%d/n“, shape); (分数:30.00)解析:(1)return 3; (2)return 1; 解析 (1)变量 a、b、c 分别表示三条边,当三边相等(a=b double sum; printf(“/n/nInput n:“); scanf(“%d“, sum=fun(n); printf(“/n/nsum=%f/n/n“, sum); (分数:40.00)_正确答案:()解析:double fun(int n) int m, k, i; double s=0.0; for(m=3; m=n; m+) k=sqrt(m); for(i=2; i=k; i+) if(m%i=0) break; if(i=k+1) s+=sqrt(m); return s; 解析 本题考查素数的判定方法及求平方根函数 sqrt 的使用。首先确定了 n 的范围,然后确定循环条件,最后根据素数的判定方法确定条件语句。

展开阅读全文
相关资源
猜你喜欢
  • STAS 9844 15-1980 TEXTILES Quantitative chemical analysis of ternary mixtures of wool polyamidic andpolyesteric fibres《织物数量 羊毛、聚酰胺和聚酯纤维三元混合物化学分析 》.pdf STAS 9844 15-1980 TEXTILES Quantitative chemical analysis of ternary mixtures of wool polyamidic andpolyesteric fibres《织物数量 羊毛、聚酰胺和聚酯纤维三元混合物化学分析 》.pdf
  • STAS 9844 16-1981 TEXTILES Quantitative analysis of ternary mixtures of polyamidic fibres with polyacrilonitrilic fibres and staple fibres《纺织品 带腈纶纤维和短纤维的聚酰胺纤维的三组分混合物的定量化学分析 》.pdf STAS 9844 16-1981 TEXTILES Quantitative analysis of ternary mixtures of polyamidic fibres with polyacrilonitrilic fibres and staple fibres《纺织品 带腈纶纤维和短纤维的聚酰胺纤维的三组分混合物的定量化学分析 》.pdf
  • STAS 9844 17-1981 TEXTILE MATERIALS Quantitative analysis of ternary mixtures of wool fibres with polyamidic fibres and polypropylenic fibres 《纺织材料 带有聚酰胺纤维和聚丙烯纤维的羊毛纤维三组分混合物的定量化学分析 .pdf STAS 9844 17-1981 TEXTILE MATERIALS Quantitative analysis of ternary mixtures of wool fibres with polyamidic fibres and polypropylenic fibres 《纺织材料 带有聚酰胺纤维和聚丙烯纤维的羊毛纤维三组分混合物的定量化学分析 .pdf
  • STAS 9844 19-1991 TEXTILES Quantative chemical analysis of ternary mixtura of wool fibres with polyesteric fibres and fiax fibres《纺织品 带聚酯纤维和亚麻纤维的羊毛纤维的三组分混合物的定量化学分析 》.pdf STAS 9844 19-1991 TEXTILES Quantative chemical analysis of ternary mixtura of wool fibres with polyesteric fibres and fiax fibres《纺织品 带聚酯纤维和亚麻纤维的羊毛纤维的三组分混合物的定量化学分析 》.pdf
  • STAS 9844 2-1975 TEXTILES Quantitative analysis of binary mixtures of cotton fibres and cellulose base man made fibres《纺织品 棉纤维和纤维素基地人造纤维二元混合物的定量分析 》.pdf STAS 9844 2-1975 TEXTILES Quantitative analysis of binary mixtures of cotton fibres and cellulose base man made fibres《纺织品 棉纤维和纤维素基地人造纤维二元混合物的定量分析 》.pdf
  • STAS 9844 20-1982 TEXTILES Quantitative chemical analysis of tehrnary mixtures of wool with silk fibres and triacetate《纺织品 带丝绸纤维和三醋酸纤维的羊毛三元混合物的定量化学分析 》.pdf STAS 9844 20-1982 TEXTILES Quantitative chemical analysis of tehrnary mixtures of wool with silk fibres and triacetate《纺织品 带丝绸纤维和三醋酸纤维的羊毛三元混合物的定量化学分析 》.pdf
  • STAS 9844 21-1982 TEXTILES Quantitative chemical analysis of ternary mixtures of wool with polyester and polypropylene fibres《织物 羊毛、聚酯和聚丙烯纤维三元混合物定量化学分析》.pdf STAS 9844 21-1982 TEXTILES Quantitative chemical analysis of ternary mixtures of wool with polyester and polypropylene fibres《织物 羊毛、聚酯和聚丙烯纤维三元混合物定量化学分析》.pdf
  • STAS 9844 22-1982 TEXTILES analyse chimique quantitative des melanges ternaires《织物 混纺织物定量化学分析》.pdf STAS 9844 22-1982 TEXTILES analyse chimique quantitative des melanges ternaires《织物 混纺织物定量化学分析》.pdf
  • STAS 9844 23-1983 TEXTTLES Quantitative chemical analysis of ternary mixtures of wool with polyester and cellulosce fibrcs《织物 有聚酯和纤维素纤维的羊毛二元混合物的定量化学分析 》.pdf STAS 9844 23-1983 TEXTTLES Quantitative chemical analysis of ternary mixtures of wool with polyester and cellulosce fibrcs《织物 有聚酯和纤维素纤维的羊毛二元混合物的定量化学分析 》.pdf
  • 相关搜索

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

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