[计算机类试卷]国家三级(网络技术)机试模拟试卷310及答案与解析.doc

上传人:jobexamine331 文档编号:495834 上传时间:2018-11-28 格式:DOC 页数:4 大小:27KB
下载 相关 举报
[计算机类试卷]国家三级(网络技术)机试模拟试卷310及答案与解析.doc_第1页
第1页 / 共4页
[计算机类试卷]国家三级(网络技术)机试模拟试卷310及答案与解析.doc_第2页
第2页 / 共4页
[计算机类试卷]国家三级(网络技术)机试模拟试卷310及答案与解析.doc_第3页
第3页 / 共4页
[计算机类试卷]国家三级(网络技术)机试模拟试卷310及答案与解析.doc_第4页
第4页 / 共4页
亲,该文档总共4页,全部预览完了,如果喜欢就下载吧!
资源描述

1、国家三级(网络技术)机试模拟试卷 310及答案与解析 一、程序设计题 1 请编制程序,要求:将文件 IN91.DAT中的 200个整数读入数组 xx中,求出数组 xx中奇数的个数 cnt1和偶数的个数 cnt2,以及数组 xx下标为偶数的元素值的算术平均值 pj(保留 2位小数 ),结果 cnt1, cnt2, pj输出到 out91.dat中。 部分程序、读函数 read_dat(int xx200)及输出格式已给出。 试题程序: #include conio.h #include stdio.h #define N 200 void read_dat (int xxN) int i,j;

2、FILE *fp; fp=fopen (“IN91.DAT“, “r“); for (i=0;i 20;i+) for (j=0; j 10; 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 (“nncnt1=%d, cnt2

3、=%d,pj=%6.2fn“, cnt1, cnt2, pj); fprintf (fw, “%dn%dn%6.2fn“, cnt1, cnt2,pj); fclose (fw); 国家三级(网络技术)机试模拟试卷 310答案与解析 一、程序设计题 1 【正确答案】 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); for(i=0,j=0,cnt1=0,cnt2=0;i N;i+) if(xxi%2) /

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

展开阅读全文
相关资源
猜你喜欢
  • AS NZS 60335 2 34-2003 Household and similar electrical appliances - Safety - Particular requirments for motor-compressors《家用及类似用途电气设备 安全性:电动压缩机的特殊要求》.pdf AS NZS 60335 2 34-2003 Household and similar electrical appliances - Safety - Particular requirments for motor-compressors《家用及类似用途电气设备 安全性:电动压缩机的特殊要求》.pdf
  • AS NZS 60335 2 35-2004 Household and similar electrical appliances - Safety - Particular requirements for instantaneous water heaters (IEC 60335-2-35 Ed 4 1 IDT)《AS NZS 60335 2 35-.pdf AS NZS 60335 2 35-2004 Household and similar electrical appliances - Safety - Particular requirements for instantaneous water heaters (IEC 60335-2-35 Ed 4 1 IDT)《AS NZS 60335 2 35-.pdf
  • AS NZS 60335 2 4-2002 Household and similar electrical appliances - Safety - Particular requirements for spin extractors《家用及类似用途电气设备 安全 特殊要求 离心式脱水机的特殊要求》.pdf AS NZS 60335 2 4-2002 Household and similar electrical appliances - Safety - Particular requirements for spin extractors《家用及类似用途电气设备 安全 特殊要求 离心式脱水机的特殊要求》.pdf
  • AS NZS 60335 2 40-2006 Household and similar electrical appliances - Safety - Particular requirements for electrical heat pumps air-conditioners and dehumidifiers (IEC 60335-2-40 E.pdf AS NZS 60335 2 40-2006 Household and similar electrical appliances - Safety - Particular requirements for electrical heat pumps air-conditioners and dehumidifiers (IEC 60335-2-40 E.pdf
  • AS NZS 60335 2 45-2004 Household and similar electrical appliances - Safety - Particular requirements for portable heating tools and similar appliances《家用及类似电气设备 安全性 电动便携式加热装置及类似设备.pdf AS NZS 60335 2 45-2004 Household and similar electrical appliances - Safety - Particular requirements for portable heating tools and similar appliances《家用及类似电气设备 安全性 电动便携式加热装置及类似设备.pdf
  • AS NZS 60335 2 54-2005 Household and similar electrical appliances - Safety - Particular requirements for surface-cleaning appliances for household use employing liquids or steam (.pdf AS NZS 60335 2 54-2005 Household and similar electrical appliances - Safety - Particular requirements for surface-cleaning appliances for household use employing liquids or steam (.pdf
  • AS NZS 60335 2 55-2004 Household and similar electrical appliances - Safety - Particular requirements for electrical appliances for use with aquariums and garden ponds《家用及类似用途电气设备 .pdf AS NZS 60335 2 55-2004 Household and similar electrical appliances - Safety - Particular requirements for electrical appliances for use with aquariums and garden ponds《家用及类似用途电气设备 .pdf
  • AS NZS 60335 2 6-2008 Household and similar electrical appliances - Safety - Particular requirements for stationary cooking ranges hobs ovens and similar appliances (IEC 60335-2-6 .pdf AS NZS 60335 2 6-2008 Household and similar electrical appliances - Safety - Particular requirements for stationary cooking ranges hobs ovens and similar appliances (IEC 60335-2-6 .pdf
  • AS NZS 60335 2 66-2004 Household and similar electrical appliances - Safety - Particular requirements for water-bed heaters《家用及类似用途电气设备 安全性:水床加热器的特殊要求》.pdf AS NZS 60335 2 66-2004 Household and similar electrical appliances - Safety - Particular requirements for water-bed heaters《家用及类似用途电气设备 安全性:水床加热器的特殊要求》.pdf
  • 相关搜索

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

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