【计算机类职业资格】三级数据库技术机试-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 上。

展开阅读全文
相关资源
猜你喜欢
  • BS EN 45510-2-6-2000 Guide for the procurement of power station equipment - Electrical equipment - Generators《发电站设备采购指南 电气设备 发电机》.pdf BS EN 45510-2-6-2000 Guide for the procurement of power station equipment - Electrical equipment - Generators《发电站设备采购指南 电气设备 发电机》.pdf
  • BS EN 45510-2-7-2002 Guide for the procurement of power station equipment - Electrical equipment - Switchgear and controlgear《电站设备的采购指南 开关设备和控制设备》.pdf BS EN 45510-2-7-2002 Guide for the procurement of power station equipment - Electrical equipment - Switchgear and controlgear《电站设备的采购指南 开关设备和控制设备》.pdf
  • BS EN 45510-2-8-2004 Guide for procurement of power station equipment - Electrical equipment - Power cables《发电站设备采购指南 电气设备 电力电缆》.pdf BS EN 45510-2-8-2004 Guide for procurement of power station equipment - Electrical equipment - Power cables《发电站设备采购指南 电气设备 电力电缆》.pdf
  • BS EN 45510-2-9-2008 Guide for procurement of power station equipment-Part 2-9 Electrical equipment - Cabling systems《发电站设备的采购指南 电气设备 布线系统》.pdf BS EN 45510-2-9-2008 Guide for procurement of power station equipment-Part 2-9 Electrical equipment - Cabling systems《发电站设备的采购指南 电气设备 布线系统》.pdf
  • BS EN 45510-3-1-2000 Guide for the procurement of power station equipment - Boilers - Water tube boilers - Section 1 Water tube boilers《发电站设备采购指南 锅炉 水管锅炉 第1节 水管锅炉》.pdf BS EN 45510-3-1-2000 Guide for the procurement of power station equipment - Boilers - Water tube boilers - Section 1 Water tube boilers《发电站设备采购指南 锅炉 水管锅炉 第1节 水管锅炉》.pdf
  • BS EN 45510-3-2-2000 Guide for the procurement of power station equipment - Boilers - Shell boilers - Section 2 Shell boilers《发电站设备采购指南 锅炉 火管锅炉 第2节 火管锅炉》.pdf BS EN 45510-3-2-2000 Guide for the procurement of power station equipment - Boilers - Shell boilers - Section 2 Shell boilers《发电站设备采购指南 锅炉 火管锅炉 第2节 火管锅炉》.pdf
  • BS EN 45510-3-3-2000 Guide for the procurement of power station equipment - Boilers - Boilers with fluidized bed firing - Section 3 Boilers with fluidised bed firing《发电站设备采购指南 锅炉 流.pdf BS EN 45510-3-3-2000 Guide for the procurement of power station equipment - Boilers - Boilers with fluidized bed firing - Section 3 Boilers with fluidised bed firing《发电站设备采购指南 锅炉 流.pdf
  • BS EN 45510-4-1-1999 Guide for the procurement of power station equipment - Boiler auxiliaries - Equipment for reduction of dust emissions - Equipment for the reduction of dust emi.pdf BS EN 45510-4-1-1999 Guide for the procurement of power station equipment - Boiler auxiliaries - Equipment for reduction of dust emissions - Equipment for the reduction of dust emi.pdf
  • BS EN 45510-4-10-2000 Guide for the procurement of power station equipment - Boiler auxiliaries - Flue gas denitrification (De-NOx) plant - Section 10 Flue gas denitrification (De-.pdf BS EN 45510-4-10-2000 Guide for the procurement of power station equipment - Boiler auxiliaries - Flue gas denitrification (De-NOx) plant - Section 10 Flue gas denitrification (De-.pdf
  • 相关搜索

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

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