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

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

1、三级网络技术机试-177 及答案解析(总分:100.00,做题时间:90 分钟)一、上机题(总题数:1,分数:100.00)1.请编制程序,要求:将文件 IN92.DAT中的 200个整数读入数组 xx中,求出数组 xx中最大数 max及最大数的个数 cnt和数组 xx中值能被 3整除或能被 7整除的数的算术平均值 pj(保留两位小数),结果max,cnt,pj 输出到 out92.dat中。部分程序、读函数 read_dat(int xx200)及输出格式已给出。试题程序:#includeconio.h#includestdio.h#define N 200void read_dat(int

2、 xxN)int i,j;FILE *fp;fp=fopen(“IN92.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 i, k, cnt, xx N,max;float pj;FILE *fw;long j=0;clrscr ();fw=fopen (“out92.dat“, “w“);read_dat (xx);printf (“/n/nmax=%d, cnt=%d, pj=%6.2f/n“, m

3、ax, cnt,pj);fprintf(fw, “%d/n%d/n%6.2f/n“,max, cnt,pj);fclose (fw);(分数:100.00)_三级网络技术机试-177 答案解析(总分:100.00,做题时间:90 分钟)一、上机题(总题数:1,分数:100.00)1.请编制程序,要求:将文件 IN92.DAT中的 200个整数读入数组 xx中,求出数组 xx中最大数 max及最大数的个数 cnt和数组 xx中值能被 3整除或能被 7整除的数的算术平均值 pj(保留两位小数),结果max,cnt,pj 输出到 out92.dat中。部分程序、读函数 read_dat(int xx

4、200)及输出格式已给出。试题程序:#includeconio.h#includestdio.h#define N 200void read_dat(int xxN)int i,j;FILE *fp;fp=fopen(“IN92.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 i, k, cnt, xx N,max;float pj;FILE *fw;long j=0;clrscr ();fw=fope

5、n (“out92.dat“, “w“);read_dat (xx);printf (“/n/nmax=%d, cnt=%d, pj=%6.2f/n“, max, cnt,pj);fprintf(fw, “%d/n%d/n%6.2f/n“,max, cnt,pj);fclose (fw);(分数:100.00)_正确答案:(void main()int i,k,cnt,xxN,max;float pj;FILE *fw;long j=0;clrscr();fw=fopen(“out92.dat“,“N“);read_dat(xx);max=xx0;for(i=1,k=0;iN;i+)if(xx

6、imax)max=xxi; /*求出数组 xx中最大数 max*/if(xxi%3= =0 |xxi%7= =0)j+=xxi; /*求出数组 xx中值能被 3整除或能被 7整除的数的总和*/k+;for(i=0,cnt=0;iN;i+)if(xxi= =max)cnt+; /*求出数组 xx中最大数 max的个数*/Pj=(float)(j*100/k)/100;/*求出数组 xx中值能被 3整除或能被 7整除的数的平均值*/printf(“/n/nmax=%d,cnt=%d,pj=%6.2f/n“,max,cnt,pj);fprintf(fw,“%d/n%d/n%6.2f/n“,max,c

7、nt,pj);fclose(fw);)解析:解析 本题考查的知识点如下:(1)运算符“%”的使用。(2)判断结构中多个条件的布尔运算。首先,要找出数组中最大的元素。先定义第 1个元素为最大的元素,然后依次和后面的元素比较,若后面的数中有大于第 1个元素的,则将这个数定义为最大的元素。再和后面的数进行比较。一个数 a除以 b取余所得的数为 0,则 a能被 b整除。根据题意可知,被 3整除和被 7整除两个条件满足一个即可,所以两个条件之间用“或”运算。在本题中,要求算术平均值保留两位小数。使用的方法是:将和乘以 100除以个数强制类型转换后再除以 100。为了保证和有效,我们定义了一个长整型变量来记录和。因为个数也为整型,运算符“/”在这里的含义是整除,而我们要保留小数,所以要使用强制类型转换将和乘以 100的结果转换为浮点类型,这样就可以实现保留两位小数。

展开阅读全文
相关资源
猜你喜欢
  • BS PD IEC TS 62763-2013_5284 Pilot function through a control pilot circuit using PWM (pulse width modulation) and a control pilot wire《通过控制导向线使用PWM (脉冲宽度调制) 的导向功能和控制导向线》.pdf BS PD IEC TS 62763-2013_5284 Pilot function through a control pilot circuit using PWM (pulse width modulation) and a control pilot wire《通过控制导向线使用PWM (脉冲宽度调制) 的导向功能和控制导向线》.pdf
  • BS ISO 8070-2007 Milk and milk products - Determination of calcium sodium potassium and magnesium contents - Atomic absorption spectrometric method《牛奶和奶制品 钙、钠、钾和镁含量的测定 原子吸.pdf BS ISO 8070-2007 Milk and milk products - Determination of calcium sodium potassium and magnesium contents - Atomic absorption spectrometric method《牛奶和奶制品 钙、钠、钾和镁含量的测定 原子吸.pdf
  • BS ISO 8082-1-2009 Self-propelled machinery for forestry - Laboratory tests and performance requirements for roll-over protective structures - General machines《林业用自推进机械 防倾.pdf BS ISO 8082-1-2009 Self-propelled machinery for forestry - Laboratory tests and performance requirements for roll-over protective structures - General machines《林业用自推进机械 防倾.pdf
  • BS ISO 8082-2-2011 Self-propelled machinery for forestry Laboratory tests and performance requirements for roll-over protective structures Machines having a rotating platf.pdf BS ISO 8082-2-2011 Self-propelled machinery for forestry Laboratory tests and performance requirements for roll-over protective structures Machines having a rotating platf.pdf
  • BS ISO 8083-2006 Machinery for forestry - Falling-object protective structures (FOPS) - Laboratory tests and performance requirements《林业机械 落体防护装置(FOPS) 实验室试验和性能要求》.pdf BS ISO 8083-2006 Machinery for forestry - Falling-object protective structures (FOPS) - Laboratory tests and performance requirements《林业机械 落体防护装置(FOPS) 实验室试验和性能要求》.pdf
  • BS ISO 8086-2004 Dairy plant - Hygiene conditions - General guidance on inspection and sampling procedures《乳品厂 卫生条件 检验和取样程序通用指南》.pdf BS ISO 8086-2004 Dairy plant - Hygiene conditions - General guidance on inspection and sampling procedures《乳品厂 卫生条件 检验和取样程序通用指南》.pdf
  • BS ISO 8096-2005 Rubber- or plastics-coated fabrics for water resistant clothing - Specification《雨衣用橡胶或塑料涂覆织物 规范》.pdf BS ISO 8096-2005 Rubber- or plastics-coated fabrics for water resistant clothing - Specification《雨衣用橡胶或塑料涂覆织物 规范》.pdf
  • BS ISO 8097-2001 Aircraft Minimum airworthiness requirements and test conditions for certified air cargo unit load devices《航空器 经认证的航空货运集装单元装置最低适航性要求和试验条件》.pdf BS ISO 8097-2001 Aircraft Minimum airworthiness requirements and test conditions for certified air cargo unit load devices《航空器 经认证的航空货运集装单元装置最低适航性要求和试验条件》.pdf
  • BS ISO 8114-1993 Textile machinery and accessories - Spindles for ring-spinning and doubling machines - List of equivalent terms《纺织机械和附件 环锭纺纱机和并线机用锭子 同义术语表》.pdf BS ISO 8114-1993 Textile machinery and accessories - Spindles for ring-spinning and doubling machines - List of equivalent terms《纺织机械和附件 环锭纺纱机和并线机用锭子 同义术语表》.pdf
  • 相关搜索

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

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