题目内容

已知在文件IN94.DAT中存有若干个(个数<200)4位数字的正整数,函数ReadDat()的功能是读取这若干个正整数并存入数组xx中。请编制函数CalValue(),其功能要求:(1)求出该文件中共有多少个正整数totNum;(2)求m这些数中的各位数字之和是偶数的数的个数totCnt,以及满足此条件的这些数的算术平均值totPjz,最后调用函数WriteDat()把所求的结果输出到文件OUT94.DAT中。 注意:部分源程序已给出。 请勿改动主函数main()、读函数ReadDat()和写函数WriteDat()的内容。 试题程序: #include <stdio.h> #include <stdlib.h> #define MAXNUM 200 int xx[MAXNUM]; int totNum=0;/*文件IN94.DAT中共有多少个正整数*/ int totCnt=0;/*符合条件的正整数的个数*/ double totPjz=0.0;/*平均值*/ int ReadDat(void); void Writedat(void); void CalValue() void main() int i; system("CLS"); for(i=0;i<MAXNUM;i + +) xx[i]=0; if(Readdat()) printf("数据文件IN94.DAT不能打开!\007\n"); return; CalValue(); printf("文件IN94.DAT中共有正整数=% d个\n",totNum); printf("符合条件的正整数的个数=% d个\n",totCnt); printf("平均值=% .21f\n",totPjz); Writedat(); int Readdat(void) FILE * fp; int i=0; if((fp=fopen("IN94.DAT","r"))==NULL) return 1; while(! feof(fp)) fscanf(fp,"% d,",&xx[i + +]); fclose(fp); return 0; void Writedat(void) FILE * fp; fp=fopen("OUT94.DAT","w"); fprintf(fp,"% d\n% d\n% .21f\n",totNum,totCnt,totPjz); fclose(fp);

查看答案
更多问题

Questions 11 to 18 are based on the conversation you have just heard.

A. She will take subway.
B. She will hurry to the conference.
C. She will skip the conference and go sightseeing.
D. She will take a bus.

Passage OneQuestions 26 to 29 are based on the passage you have just heard.

A. The climate.
B. One’s social position.
C. The materials available.
D. Family size.

Passage OneQuestions 26 to 29 are based on the passage you have just heard.

A. Human Basic Needs.
B. Material Comfort.
C. Food: Human Basic Need.
D. Basic Necessities of Life.

Passage OneQuestions 26 to 29 are based on the passage you have just heard.

A. It is needed to adjust the temperature of our bodies.
B. It is our second need.
C. We need it to cover our bodies.
D. Weather is changing all the time.

答案查题题库