全国计算机等级考试四级计算机题库
第一集
===============================================================================
试题描述:
===============================================================================
已知有几个(数量
Number,函数ReadDat()读取这些正整数,并将它们存储在数组xx中。请
编译函数CalValue(),其函数要求为:1。找出这个文件中* * *有多少。
正整数totNum2.找出数字总和为奇数的数字。
满足这个条件的数totCnt和这些数的算术平均值totPjz,最
之后,调用函数WriteDat()将所需结果输出到文件OUT1.DAT。
注意:部分源程序存储在PROG1中。C
不要改变主函数main(),读取数据函数ReadDat()和输出数据。
函数WriteDat()的内容。
===============================================================================
程序:
===============================================================================
#包括
#包括
#定义最大数量200
int xx[MAXNUM];
int tot num = 0;/* IN的文件中有多少个正整数* *个。DAT * *
int tot CNT = 0;/*合格正整数的个数*/
double totPjz = 0.0/*平均值*/
int read dat(void);
void WriteDat(void);
空CalValue(空)
{
}
void main()
{
clr SCR();
if(ReadDat()) {
Printf("数据文件在。DAT无法打开!\ 007 \ n ");
返回;
}
CalValue();
Printf ("* *在。DAT有正整数=%d \n”,totNum);
Printf("合格正整数的个数=%d \n ",tot CNT);
Printf ("average =%.2lf\n ",totPjz);
write dat();
}
int ReadDat(void)
{
FILE * fp
int I = 0;
if((fp = fopen("in.dat "," r ")= = NULL)返回1;
而(!feof(fp)) {
fscanf(fp," %d,",& ampxx[i++]);
}
fclose(FP);
返回0;
}
void WriteDat(void)
{
FILE * fp
fp = fopen("OUT1。DAT”、“w”);
fprintf(fp," %d\n%d\n%.2lf\n ",totNum,totCnt,totPjz);
fclose(FP);
}
===============================================================================
所需数据:
===============================================================================
@2英寸。DAT 016
6045,6192,1885,3580,8544,6826,5493,8415,3132,5841,
6561,3173,9157,2895,2851,6082,5510,9610,5398,5273,
3438,1800,6364,6892,9591,3120,8813,2106,5505,1085,
5835,7295,6131,9405,6756,2413,6274,9262,5728,2650,
6266,5285,7703,1353,1510,2350,4325,4392,7573,8204,
7358,6365,3135,9903,3055,3219,3955,7313,6206,1631,
5869,5893,4569,1251,2542,5740,2073,9805,1189,7550,
4362,6214,5680,8753,8443,3636,4495,9643,3782,5556,
1018,9729,8588,2797,4321,4714,9658,8997,2080,5912,
9968,5558,9311,7047,6138,7618,5448,1466,7075,2166,
4025,3572,9605,1291,6027,2358,1911,2747,7068,1716,
9661,5849,3210,2554,8604,8010,7947,3685,2945,4224,
7014,9058,6259,9503,1615,1060,7787,8983,3822,2471,
5146,7066,1029,1777,7788,2941,3538,2912,3096,7421,
9175,6099,2930,4685,8465,8633,2628,7155,4307,9535,
4274,2857,6829,6226,8268,9377,9415,9059,4872,6072,
#E
@3 $OUT1。DAT 003
|160\|69\|5460.51
#E
更多阅读试题网计算机等级考试专栏。
Http://www.shiti.org/zgrz/jsj/Index.htm对历年的等级考试都有真题。