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

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

1、计算机三级数据库技术-148 及答案解析(总分:100.00,做题时间:90 分钟)一、上机题(总题数:1,分数:100.00)1.已知数据文件 IN.DAT 中存有 300 个 4 位数,并已调用读函数 readDat()把这些数存入数组 a 中,请编写函数 jsValue(),其功能是:求出这些 4 位数中素数的个数 cnt,再把所有满足此条件的 4 位数依次存入数组 b 中,然后对数组 b 的 4 位数按从小到大的顺序进行排序,最后调用函数 writeDat(),把数组 b中的数输出到 OUT.DAT 文件中。 例如,5591 是素数,则该数满足条件,存入数组 b 中,且个数 cnt=c

2、nt+1。 9812 是非素数,则该数不满足条件,忽略。 注意:程序中已定义数组 a300、b300,已定义变量 cnt。请勿改动主函数 main()、读函数 readDat()和写函数 writeDat()的内容。 【试题程序】 #include stdio .h int a300,b300,cnt=0; void readDat () ; void writeDat () ; int isP (int m) int i ; for (i =2;i m;i + ) if (m%i = 0 ) return 0 ; return 1 ; void jsValue () void main ()

3、 int i ; readDat () ; j sValue () ; writeDat () ; printf (“cnt =%dn“, cnt) ; for (i =0;i cnt;i + ) printf (“b%d =%dn“,i,bi) ; void readDat () FILE * fp; int i ; fp = fopen ( “IN. DAT“, “r“ ) ; for (i =0;i 300;i + ) fscanf (fp, “%d, “, fclose (fp) ; void writeDat () FILE * fp; int i; fp = fopen ( “OU

4、T. DAT“, “w“ ) ; fprintf (fp, “%dn“, cnt) ; for(i=0;icnt;i+) fprintf (fp, “%dn“,bi ) ; fclose (fp) ; (分数:100.00)_计算机三级数据库技术-148 答案解析(总分:100.00,做题时间:90 分钟)一、上机题(总题数:1,分数:100.00)1.已知数据文件 IN.DAT 中存有 300 个 4 位数,并已调用读函数 readDat()把这些数存入数组 a 中,请编写函数 jsValue(),其功能是:求出这些 4 位数中素数的个数 cnt,再把所有满足此条件的 4 位数依次存入数组

5、b 中,然后对数组 b 的 4 位数按从小到大的顺序进行排序,最后调用函数 writeDat(),把数组 b中的数输出到 OUT.DAT 文件中。 例如,5591 是素数,则该数满足条件,存入数组 b 中,且个数 cnt=cnt+1。 9812 是非素数,则该数不满足条件,忽略。 注意:程序中已定义数组 a300、b300,已定义变量 cnt。请勿改动主函数 main()、读函数 readDat()和写函数 writeDat()的内容。 【试题程序】 #include stdio .h int a300,b300,cnt=0; void readDat () ; void writeDat (

6、) ; int isP (int m) int i ; for (i =2;i m;i + ) if (m%i = 0 ) return 0 ; return 1 ; void jsValue () void main () int i ; readDat () ; j sValue () ; writeDat () ; printf (“cnt =%dn“, cnt) ; for (i =0;i cnt;i + ) printf (“b%d =%dn“,i,bi) ; void readDat () FILE * fp; int i ; fp = fopen ( “IN. DAT“, “r“

7、 ) ; for (i =0;i 300;i + ) fscanf (fp, “%d, “, fclose (fp) ; void writeDat () FILE * fp; int i; fp = fopen ( “OUT. DAT“, “w“ ) ; fprintf (fp, “%dn“, cnt) ; for(i=0;icnt;i+) fprintf (fp, “%dn“,bi ) ; fclose (fp) ; (分数:100.00)_正确答案:()解析:void jsValue() int i,j; /*定义循环控制变量*/ int temp; /*定义数据交换是的暂存变量*/ f

8、or(i=0;i300;i+) /*逐个取 4 位数*/ if(isP(ai) /*如果该数为素数,则将该数存入数组 b 中*/ bcnt=ai; cnt+; /*并统计满足条件的数的个数*/ for(i=0;icnt-1;i+) /*对数组 b 的 4 位数按从小到大的顺序进行排序*/ for(j=i+1;jcnt;j+) if(bibj) temp=bi; bi=bj; bj=temp; 解析 本题属于数学类题。根据题意可知,函数 jsValue()要实现两个功能:一是找出为素数的数,并存放在数组 b 中;二是对数组 b 中的数进行从小到大的排序。 首先要找出满足条件的数,即素数,题目中已给出了判断素数的函数,因此只需调用即可。 其次,将这些素数存入数组 b 中,并用变量 cnt 来统计数组 b 中元素的个数。 最后,将所有满足条件的数取出后利用起泡法进行排序,即将当前元素依次同它后面的元素进行比较,发现有大于该数的数,就将这两个数进行交换。

展开阅读全文
相关资源
猜你喜欢
  • CAN CSA-C50064-1999 Wrought aluminium and aluminium alloy enclosures for gas-filled high-voltage switchgear and controlgear (First Edition General Instruction No 1 April 1999).pdf CAN CSA-C50064-1999 Wrought aluminium and aluminium alloy enclosures for gas-filled high-voltage switchgear and controlgear (First Edition General Instruction No 1 April 1999).pdf
  • CAN CSA-C50068-1999 Wrought steel enclosures for gas-filled high-voltage switchgear and controIgear (First Edition General Instruction No 1 April 1999).pdf CAN CSA-C50068-1999 Wrought steel enclosures for gas-filled high-voltage switchgear and controIgear (First Edition General Instruction No 1 April 1999).pdf
  • CAN CSA-C50069-1999 Welded composite enclosures of cast and wrought aluminium alloys for gas-filled highvoltage switchgear and controlgear (First Edition General Instruction No 1 A.pdf CAN CSA-C50069-1999 Welded composite enclosures of cast and wrought aluminium alloys for gas-filled highvoltage switchgear and controlgear (First Edition General Instruction No 1 A.pdf
  • CAN CSA-C50089-1999 Cast Resin Partitions for Metal-Enclosed Gas-Filled High-Voltage Switchgear and Controlgear (First Edition General Instrucion No 1 April 1999).pdf CAN CSA-C50089-1999 Cast Resin Partitions for Metal-Enclosed Gas-Filled High-Voltage Switchgear and Controlgear (First Edition General Instrucion No 1 April 1999).pdf
  • CAN CSA-C60871-1-2014 Shunt capacitors for a c power systems having a rated voltage above 1 000 V - Part 1 General (Third Edition).pdf CAN CSA-C60871-1-2014 Shunt capacitors for a c power systems having a rated voltage above 1 000 V - Part 1 General (Third Edition).pdf
  • CAN CSA-C61000-2-7-2004 Electromagnetic compatibility (EMC) – Part 2 Environment - Section 7 Low frequency magnetic fields in various environments (First Edition).pdf CAN CSA-C61000-2-7-2004 Electromagnetic compatibility (EMC) – Part 2 Environment - Section 7 Low frequency magnetic fields in various environments (First Edition).pdf
  • CAN CSA-C61000-3-11-2006 Electromagnetic compatibility (EMC) – Part 3-11 Limits – Limitation of voltage changes voltage fluctuations and flicker in public low-voltage supply systee.pdf CAN CSA-C61000-3-11-2006 Electromagnetic compatibility (EMC) – Part 3-11 Limits – Limitation of voltage changes voltage fluctuations and flicker in public low-voltage supply systee.pdf
  • CAN CSA-C61000-3-13-2009 Electromagnetic compatibility (EMC) - Part 3-13 Limits - Assessment of emission limits for the connection of unbalanced installations to MV HV and EHV powe.pdf CAN CSA-C61000-3-13-2009 Electromagnetic compatibility (EMC) - Part 3-13 Limits - Assessment of emission limits for the connection of unbalanced installations to MV HV and EHV powe.pdf
  • CAN CSA-C61000-3-14-2015 Electromagnetic compatibility (EMC) - Part 3-14 Assessment of emission limits for harmonics interharmonics voltage fluctuations and unbalance for the conne.pdf CAN CSA-C61000-3-14-2015 Electromagnetic compatibility (EMC) - Part 3-14 Assessment of emission limits for harmonics interharmonics voltage fluctuations and unbalance for the conne.pdf
  • 相关搜索

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

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