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

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

1、国家三级(网络技术)机试模拟试卷 91及答案与解析 一、程序设计题 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; F

2、ILE *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); 国家三级(网络技术)机试模拟试卷 91答案与解析 一、程序设计题 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的结果转换为浮点类型,这样就可以实现保留两位小数。使用循环对所有数据进行访问。 【知识模块】 三级网络技术机试模拟

展开阅读全文
相关资源
猜你喜欢
  • ANSI ISO IEC 8632-4-1999 Information technology Computer graphics Metafile for the storage and transfer of picture description information Part 4 Clear text encoding (Adopted by IN.pdf ANSI ISO IEC 8632-4-1999 Information technology Computer graphics Metafile for the storage and transfer of picture description information Part 4 Clear text encoding (Adopted by IN.pdf
  • ANSI ISO IEC 8652-1995 for Information Technology - Programming Languages - Ada (Adopted by INCITS)《信息技术.编程语言.INCITS采纳的Ada语言》.pdf ANSI ISO IEC 8652-1995 for Information Technology - Programming Languages - Ada (Adopted by INCITS)《信息技术.编程语言.INCITS采纳的Ada语言》.pdf
  • ANSI ISO IEC 8824-1-1998 Information technology Abstract Syntax Notation One (ASN.1) Specification of basic notation Adopted by INCITS Amendment 2 10 15 2000《信息技术.抽象语法记法1(ASN.1) IN.pdf ANSI ISO IEC 8824-1-1998 Information technology Abstract Syntax Notation One (ASN.1) Specification of basic notation Adopted by INCITS Amendment 2 10 15 2000《信息技术.抽象语法记法1(ASN.1) IN.pdf
  • ANSI ISO IEC 8824-4-1998 Information technology Abstract Syntax Notation One (ASN.1) Parameterization of ASN.1 specifications Adopted by INCITS Amendment 1 12 01 2000《信息技术.抽象语法记法1(.pdf ANSI ISO IEC 8824-4-1998 Information technology Abstract Syntax Notation One (ASN.1) Parameterization of ASN.1 specifications Adopted by INCITS Amendment 1 12 01 2000《信息技术.抽象语法记法1(.pdf
  • ANSI ISO IEC 8825-1-1998 Information technology ASN.1 encoding rules Specification of Basic Encoding Rules (BER) Canonical Encoding Rules (CER) and Distinguished Encoding Rules (DE.pdf ANSI ISO IEC 8825-1-1998 Information technology ASN.1 encoding rules Specification of Basic Encoding Rules (BER) Canonical Encoding Rules (CER) and Distinguished Encoding Rules (DE.pdf
  • ANSI ISO IEC 8825-2-1998 Information technology ASN.1 encoding rules Specification of Packed Encoding Rules (PER) Adopted by INCITS Amendment 1 12 01 2000《信息技术.ASN.1编码规则 INCITS采用的包.pdf ANSI ISO IEC 8825-2-1998 Information technology ASN.1 encoding rules Specification of Packed Encoding Rules (PER) Adopted by INCITS Amendment 1 12 01 2000《信息技术.ASN.1编码规则 INCITS采用的包.pdf
  • ANSI ISO IEC 9070-1991 Information technology - SGML support facilities - Registration procedures for public text owner identifiers (Adopted by INCITS)《信息技术.标准通用标示语言(SGML)支持设施.INCI.pdf ANSI ISO IEC 9070-1991 Information technology - SGML support facilities - Registration procedures for public text owner identifiers (Adopted by INCITS)《信息技术.标准通用标示语言(SGML)支持设施.INCI.pdf
  • ANSI ISO IEC 9075-5-1999 Information Technology Database Language SQL Part 5 Host Language Bindings (SQL Bindings) (Adopted by INCITS Technical Corrigendum 1 12 15 2000 Amendment 1.pdf ANSI ISO IEC 9075-5-1999 Information Technology Database Language SQL Part 5 Host Language Bindings (SQL Bindings) (Adopted by INCITS Technical Corrigendum 1 12 15 2000 Amendment 1.pdf
  • ANSI ISO IEC 9171-1-1990 Information technology - 130 mm optical disk cartridge write once for information interchange - Part 1 Unrecorded optical disk cartridge (Adopted by INCITS.pdf ANSI ISO IEC 9171-1-1990 Information technology - 130 mm optical disk cartridge write once for information interchange - Part 1 Unrecorded optical disk cartridge (Adopted by INCITS.pdf
  • 相关搜索

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

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