【计算机类职业资格】三级数据库技术机试-188及答案解析.doc

上传人:lawfemale396 文档编号:1321229 上传时间:2019-10-17 格式:DOC 页数:3 大小:28.50KB
下载 相关 举报
【计算机类职业资格】三级数据库技术机试-188及答案解析.doc_第1页
第1页 / 共3页
【计算机类职业资格】三级数据库技术机试-188及答案解析.doc_第2页
第2页 / 共3页
【计算机类职业资格】三级数据库技术机试-188及答案解析.doc_第3页
第3页 / 共3页
亲,该文档总共3页,全部预览完了,如果喜欢就下载吧!
资源描述

1、三级数据库技术机试-188 及答案解析(总分:100.00,做题时间:90 分钟)一、上机题(总题数:1,分数:100.00)1.程序 test.c 的功能是:计算 100 以内满足以下条件的所有整数 i 的个数 cnt 以及这些 i 之和 sum。条件:i,i+4,i+10 都是素数,同时 i+10 小于 100。请考生编写函数 countValue()实现程序要求,最后调用函数 writeDAT()把结果 cnt 和 sum 输出到文件 out.dat 中。(数值 1 不是素数)注意:部分源程序存放在 test.c 文件中。请勿改动主函数 main()和输出数据函数 writeDAT()的

2、内容。#include stdio.h /include 语句说明各程序中包含 vc6.0 中的标准输入输出库函数 stdio.hvoid writeDAT(); /函数 writeDAT()的声明语句int cnt,sum; /定义全局整型变量 cnt,sumint isPrime (int number) /函数 isPrime (number)判断 number 是否是素数,如果是素数,则返回 tag的值等于 1,否则返回 tag 的值等于 0int i,tag=1; /定义变量 i 和 tag,并且赋变量 tag 的初值等于 1if(number=1)return 0; /如果 num

3、ber 的值等于 1,则返回 0for (i=2; tag 1+) /变量 i 从 2 开始,每次加 1,直到其值小于等于 number/2 并且变量 tag 的值等于 1 时,退出循环if(number %i=0)tag=0; /如果 number 能被 i 整除,则变量 tag 的值等于 0return tag; /返回变量 tag 的值void countValue()void main()icnt=sum=0; /给全局变量 cnt,sum 赋初值 0countValue(); /调用函数进行计算printf(“满足条件的整数个数=%d/n“,cnt); /在屏幕上输出满足条件的整数个

4、数 cntprintf(“满足条件的整数的和值=%d/n“,sum); /在屏幕上输出满足条件的整数的和 sumwriteDAT();/把计算结果写入到文件 out.dat 中void writeDAT()FILE *fp; /定义文件指针 fpfp=fopen(“out.dat“,“w“); /以只写的方式的打开文件 out.dat,并且 fp 指向此文件fprintf(fp,“%d/n%d/n“,cnt,sum); /把素数的个数值 cnt,和的值 sum 写入到文件 out.datfclose(fp); /关闭文件 out.dat(分数:100.00)_三级数据库技术机试-188 答案解

5、析(总分:100.00,做题时间:90 分钟)一、上机题(总题数:1,分数:100.00)1.程序 test.c 的功能是:计算 100 以内满足以下条件的所有整数 i 的个数 cnt 以及这些 i 之和 sum。条件:i,i+4,i+10 都是素数,同时 i+10 小于 100。请考生编写函数 countValue()实现程序要求,最后调用函数 writeDAT()把结果 cnt 和 sum 输出到文件 out.dat 中。(数值 1 不是素数)注意:部分源程序存放在 test.c 文件中。请勿改动主函数 main()和输出数据函数 writeDAT()的内容。#include stdio.

6、h /include 语句说明各程序中包含 vc6.0 中的标准输入输出库函数 stdio.hvoid writeDAT(); /函数 writeDAT()的声明语句int cnt,sum; /定义全局整型变量 cnt,sumint isPrime (int number) /函数 isPrime (number)判断 number 是否是素数,如果是素数,则返回 tag的值等于 1,否则返回 tag 的值等于 0int i,tag=1; /定义变量 i 和 tag,并且赋变量 tag 的初值等于 1if(number=1)return 0; /如果 number 的值等于 1,则返回 0fo

7、r (i=2; tag 1+) /变量 i 从 2 开始,每次加 1,直到其值小于等于 number/2 并且变量 tag 的值等于 1 时,退出循环if(number %i=0)tag=0; /如果 number 能被 i 整除,则变量 tag 的值等于 0return tag; /返回变量 tag 的值void countValue()void main()icnt=sum=0; /给全局变量 cnt,sum 赋初值 0countValue(); /调用函数进行计算printf(“满足条件的整数个数=%d/n“,cnt); /在屏幕上输出满足条件的整数个数 cntprintf(“满足条件的

8、整数的和值=%d/n“,sum); /在屏幕上输出满足条件的整数的和 sumwriteDAT();/把计算结果写入到文件 out.dat 中void writeDAT()FILE *fp; /定义文件指针 fpfp=fopen(“out.dat“,“w“); /以只写的方式的打开文件 out.dat,并且 fp 指向此文件fprintf(fp,“%d/n%d/n“,cnt,sum); /把素数的个数值 cnt,和的值 sum 写入到文件 out.datfclose(fp); /关闭文件 out.dat(分数:100.00)_正确答案:(int i; /定义变量 ifor (i=3; i90;

9、i+) /循环变量 i 从 3 开始,依次递增,直到小于 90if (isPrime (i) sum+=i; /变量 cnt 加 1,变量 i 累加到 sum)解析:解析 100 以内(含 100)满足 i、i+4、i+10 都是素数的整数的个数以及这些 i 之和。解题思路首先定义循环变量 i,然后将 i 的值赋初值为 3,每循环一次则将 i 的值加 1,直到 i90。在 for 循环中,每执行一次循环则调用函数 isPrime()(该函数具体的算法已经在源程序中给出,直接调用即可),对 i、i+4、i+10 是否同时是素数进行判断,如果这三个数同时为素数,则计数变量 cnt 值加1,同将时将变量 i 的值累加到 sum 上。

展开阅读全文
相关资源
猜你喜欢
  • DIN EN 4632-005-2010 de en 7219 Aerospace series - Weldability and brazeability of materials in aerospace constructions - Part 005 Homogeneous assemblies of heat resisting Ni or Co.pdf DIN EN 4632-005-2010 de en 7219 Aerospace series - Weldability and brazeability of materials in aerospace constructions - Part 005 Homogeneous assemblies of heat resisting Ni or Co.pdf
  • DIN EN 4632-006-2013 Aerospace series - Weldability and brazeability of materials in aerospace constructions - Part 006 Homogeneous assemblies of titanium alloys German version EN .pdf DIN EN 4632-006-2013 Aerospace series - Weldability and brazeability of materials in aerospace constructions - Part 006 Homogeneous assemblies of titanium alloys German version EN .pdf
  • DIN EN 4634-2011 Aerospace series - Screws 100 countersunk head six lobe recess short thread in heat resisting steel FE-PA2601 (A286) passivated - Classification 900 MPa (at ambien.pdf DIN EN 4634-2011 Aerospace series - Screws 100 countersunk head six lobe recess short thread in heat resisting steel FE-PA2601 (A286) passivated - Classification 900 MPa (at ambien.pdf
  • DIN EN 4635-2010 de en 7585 Aerospace series - Screws 100 countersunk head six lobes recess short thread in heat resisting nickel base alloy NI-PH2601 (Inconel 718) - Classificatio.pdf DIN EN 4635-2010 de en 7585 Aerospace series - Screws 100 countersunk head six lobes recess short thread in heat resisting nickel base alloy NI-PH2601 (Inconel 718) - Classificatio.pdf
  • DIN EN 4636-2010 de en 2941 Aerospace series - Screws 100 countersunk head six lobe recess short thread in titanium alloy TI-P64001 with aluminium pigmented coating - Classificatio.pdf DIN EN 4636-2010 de en 2941 Aerospace series - Screws 100 countersunk head six lobe recess short thread in titanium alloy TI-P64001 with aluminium pigmented coating - Classificatio.pdf
  • DIN EN 4637-2011 Aerospace series - Blast media - White corundum German and English version EN 4637 2010《航空航天系列 喷砂介质 白刚玉 德文和英文版本EN 4637-2010》.pdf DIN EN 4637-2011 Aerospace series - Blast media - White corundum German and English version EN 4637 2010《航空航天系列 喷砂介质 白刚玉 德文和英文版本EN 4637-2010》.pdf
  • DIN EN 4638-2011 Aerospace series - Blast media - Brown corundum without iron German and English version EN 4638 2010《航空航天系列 喷砂介质 不含铁的褐色刚玉 德文版本和英文版本EN 4638-2010》.pdf DIN EN 4638-2011 Aerospace series - Blast media - Brown corundum without iron German and English version EN 4638 2010《航空航天系列 喷砂介质 不含铁的褐色刚玉 德文版本和英文版本EN 4638-2010》.pdf
  • DIN EN 4639-001-2009 Aerospace series - Connectors optical rectangular modular multicontact 1 25 diameter ferrule with removable alignment sleeve holder - Part 001 Technical specif.pdf DIN EN 4639-001-2009 Aerospace series - Connectors optical rectangular modular multicontact 1 25 diameter ferrule with removable alignment sleeve holder - Part 001 Technical specif.pdf
  • DIN EN 4639-002-2009 de en 9829 Aerospace series - Connectors optical rectangular modular multicontact 1 25 diameter ferrule with removable alignment sleeve holder - Part 002 List .pdf DIN EN 4639-002-2009 de en 9829 Aerospace series - Connectors optical rectangular modular multicontact 1 25 diameter ferrule with removable alignment sleeve holder - Part 002 List .pdf
  • 相关搜索

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

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