【计算机类职业资格】三级网络技术机试-170及答案解析.doc

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

1、三级网络技术机试-170 及答案解析(总分:100.00,做题时间:90 分钟)一、上机题(总题数:1,分数:100.00)1.请编制程序,要求:将文件 IN91.DAT中的 200个整数读入数组 xx中,求出数组 xx中奇数的个数 cnt1和偶数的个数 cnt2,以及数组 xx下标为偶数的元素值的算术平均值 pj(保留 2位小数),结果cnt1,cnt2,pj 输出到 out91.dat中。部分程序、读函数 read_dat(int xx200)及输出格式已给出。试题程序:#includeconio.h#includestdio.h#define N 200void read_dat (in

2、t xxN)int i,j;FILE *fp;fp=fopen (“IN91.DAT“, “r“);for (i=0;i20;i+)for (j=0; j10; j+)fscanf (fp, “%d, “, printf (“%d“, xx i*10+j);printf (“/n“);fclose (fp);void main ()int cnt1,cnt2,xxN;float pj;FILE *fw;int i, k=0;long j;clrscr ();fw=fopen (“out91.dat“, “w“);read_dat (xx);printf (“/n/ncnt1=%d, cnt2=

3、d,pj=%6.2f/n“, cnt1, cnt2, pj);fprintf (fw, “%d/n%d/n%6.2f/n“, cnt1, cnt2,pj);fclose (fw);(分数:100.00)_三级网络技术机试-170 答案解析(总分:100.00,做题时间:90 分钟)一、上机题(总题数:1,分数:100.00)1.请编制程序,要求:将文件 IN91.DAT中的 200个整数读入数组 xx中,求出数组 xx中奇数的个数 cnt1和偶数的个数 cnt2,以及数组 xx下标为偶数的元素值的算术平均值 pj(保留 2位小数),结果cnt1,cnt2,pj 输出到 out91.dat中。

4、部分程序、读函数 read_dat(int xx200)及输出格式已给出。试题程序:#includeconio.h#includestdio.h#define N 200void read_dat (int xxN)int i,j;FILE *fp;fp=fopen (“IN91.DAT“, “r“);for (i=0;i20;i+)for (j=0; j10; j+)fscanf (fp, “%d, “, printf (“%d“, xx i*10+j);printf (“/n“);fclose (fp);void main ()int cnt1,cnt2,xxN;float pj;FILE

5、 *fw;int i, k=0;long j;clrscr ();fw=fopen (“out91.dat“, “w“);read_dat (xx);printf (“/n/ncnt1=%d, cnt2=%d,pj=%6.2f/n“, cnt1, cnt2, pj);fprintf (fw, “%d/n%d/n%6.2f/n“, cnt1, cnt2,pj);fclose (fw);(分数:100.00)_正确答案:(void main()int cnt1,cnt2,xxN;float pj;FILE *fw;int i,k=0;long j;clrscr();fw=fopen(“out91.

6、dat“,“w“);read_dat(xx);for(i=0,j=0,cnt1=0,cnt2=0;iN;i+)if(xxi%2) /*求出数组 XX中奇数的个数 cnt1*/cnt1+;elsecnt2+; /*求出数组 xx中偶数的个数 cnt2*/if(i%2=0)j+=xxi; /*求数组 xx下标为偶数的元素值的总和*/k+;Pj=(float)(j*100/k)/100; /*求数组 xx下标为偶数的元素值的算术平均值 pj*/printf(“/n/ncnt1=%d,cnt2=%d,pj=%6.2f/n“,cnt1,cnt2,pj);fprintf(fw,“%d/n%d/n%6.2f/n“,cnt1,cnt2,pj);fclose(fw);)解析:解析 本题考查的知识点如下:(1)运算符“%”的使用。(2)强制类型转换和小数位数的保留;一个数除以 2取余所得的数为 1,则它是奇数,否则是偶数,取余使用运算符“%”。在本题中,要求算术平均值保留两位小数。使用的方法是:将和乘以 100除以个数强制类型转换后再除以 100。为了保证和有效,我们定义一个长整型变量来记录和。因为个数也为整型,运算符“/”在这里的含义是整除,而我们要保留小数,所以要使用强制类型转换将和乘以 100的结果转换为浮点类型,这样就可以实现保留两位小数。使用循环对所有数据进行访问。

展开阅读全文
相关资源
猜你喜欢
  • ASTM D5336-2009 Standard Specification for Polyphthalamide (PPA) Injection Molding Materials《聚邻苯二酰胺(PPA)喷射模铸材料的标准规范》.pdf ASTM D5336-2009 Standard Specification for Polyphthalamide (PPA) Injection Molding Materials《聚邻苯二酰胺(PPA)喷射模铸材料的标准规范》.pdf
  • ASTM D5336-2015 Standard Classification System and Basis for Specification for Polyphthalamide (PPA) Injection Molding Materials《聚邻苯二甲酰胺 (PPA) 喷射模铸材料规格的标准分类系统和基础》.pdf ASTM D5336-2015 Standard Classification System and Basis for Specification for Polyphthalamide (PPA) Injection Molding Materials《聚邻苯二甲酰胺 (PPA) 喷射模铸材料规格的标准分类系统和基础》.pdf
  • ASTM D5336-2015a Standard Classification System and Basis for Specification for Polyphthalamide (PPA) Injection Molding Material《苯丙醇胺 (PPA) 注塑成型材料规格的标准分类系统和基础》.pdf ASTM D5336-2015a Standard Classification System and Basis for Specification for Polyphthalamide (PPA) Injection Molding Material《苯丙醇胺 (PPA) 注塑成型材料规格的标准分类系统和基础》.pdf
  • ASTM D5337-2004 Standard Practice for Flow Rate for Calibration of Personal Sampling Pumps《小型取样泵校正用流率的标准规程》.pdf ASTM D5337-2004 Standard Practice for Flow Rate for Calibration of Personal Sampling Pumps《小型取样泵校正用流率的标准规程》.pdf
  • ASTM D5337-2011 Standard Practice for Flow Rate for Calibration of Personal Sampling Pumps《个人采样泵校正流量的标准操作规程》.pdf ASTM D5337-2011 Standard Practice for Flow Rate for Calibration of Personal Sampling Pumps《个人采样泵校正流量的标准操作规程》.pdf
  • ASTM D5337-2011(2016) Standard Practice for Flow Rate Adjustment of Personal Sampling Pumps《个人取样泵流量调节的标准实施规程》.pdf ASTM D5337-2011(2016) Standard Practice for Flow Rate Adjustment of Personal Sampling Pumps《个人取样泵流量调节的标准实施规程》.pdf
  • ASTM D5338-1998(2003) Standard Test Method for Determining Aerobic Biodegradation of Plastic Materials Under Controlled Composting Conditions《在受控合成条件下测定塑料材料需氧的生物降解的标准试验方法》.pdf ASTM D5338-1998(2003) Standard Test Method for Determining Aerobic Biodegradation of Plastic Materials Under Controlled Composting Conditions《在受控合成条件下测定塑料材料需氧的生物降解的标准试验方法》.pdf
  • ASTM D5338-2011 Standard Test Method for Determining Aerobic Biodegradation of Plastic Materials Under Controlled Composting Conditions Incorporating Thermophilic Temperatures《测定受控.pdf ASTM D5338-2011 Standard Test Method for Determining Aerobic Biodegradation of Plastic Materials Under Controlled Composting Conditions Incorporating Thermophilic Temperatures《测定受控.pdf
  • ASTM D5338-2015 Standard Test Method for Determining Aerobic Biodegradation of Plastic Materials Under Controlled Composting Conditions Incorporating Thermophilic Temperatures《测定受控.pdf ASTM D5338-2015 Standard Test Method for Determining Aerobic Biodegradation of Plastic Materials Under Controlled Composting Conditions Incorporating Thermophilic Temperatures《测定受控.pdf
  • 相关搜索

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

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