C语言编程(三级考试题)

来源:百度知道 编辑:UC知道 时间:2024/07/04 07:04:25
已知在文件IN56.DAT中存有若干个(个数<200)4位数字的正整数,函数ReadDat()是读取这若干个正整数并存入数组xx中。请编制函数CalValue(),其功能要求是:(1)求出这个文件中共有多少个正整数totNum。(2)求出这些数中的各位数字之和是奇数的个数totCnt,以及满足此条件的这些数的算术平均值totPjz。最后,调用函数WriteDat()把所有结果输出到文件OUT56.DAT中。
注意:部分源程序已给出。请勿改动主函数main()、读数据函数ReadDat()和输出数据函数WriteDat()的内容。
【试题程序】
#include <stdio.h>
#include <conio.h>
#include <windows.h>
#define MAXNUM 200
int xx[MAXNUM];
int totNum=0;
int totCnt=0;
double totPjz=0.0;
int ReadDat(void);
void WriteDat(void);
void CalValue(void)
{

}
void main()
{
int I;
system("cls");
for(i=0;i<MAXNUM;i++) xx[i]=0;
if(ReadDat())
{
printf("数据文件IN56.DAT不能打开!\007\n");
return;
}
CalValue();
printf("文件IN56.DAT中共有正整数=%d个\n",totNum);
printf("符合条件的正整数的个数=%d个\n",totCnt);
printf("平均值=%.2lf\n",t

void CalValue(void)
{ int i ,qw,bw,sw,gw;
for(i=0;i<MAXNUM;i++)
if(xx[i]>0)
{ totNum++;
qw=xx[i]/1000; bw=xx[i]/100%10;
sw=xx[i]%100/10; gw=xx[i]%10;
if((qw+bw+sw+gw)%2) { totCnt++; totPjz+=xx[i];}
}
if(totCnt==0) totPjz=0;
else totPjz/=totCnt;
}

我这有三级上机考试题word文档,你需要吗/