标题:这个程序有错吗?
取消只看楼主
zwlcdh
Rank: 1
等 级:新手上路
帖 子:83
专家分:0
注 册:2007-2-8
 问题点数:0 回复次数:2 
这个程序有错吗?

c文件的目录里有in.dat文件,可怎么老是说没有啊!?!?帮忙解答一下。in.dat传上了

#include <stdio.h>
#include <conio.h>
#define MAXNUM 200

int xx[MAXNUM];
int totNum=0; /*文件IN.DAT中共有多少个正整数*/
int totCnt=0; /*符合条件的正整数的个数*/
double totPjz=0.0; /*平均值*/

int ReadDat(void);
void writeDat(void);

void CalValue(void)
{int i;
for(i=0;i<MAXNUM;i++)
if(xx[i]>0)
{totNum++;
if((xx[i]>>1)%2==0)
{totCnt++;totNum+=xx[i];
}
}
totNum/=totCnt;
}

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

int ReadDat(void) /*主要看看这个函数有什么毛病!!!!!谢谢啦!!!*/
{
FILE *fp;
int i=0;

if((fp=fopen("IN.DAT","r"))==NULL) return 1;
while(!feof(fp)){
fscanf(fp,"%d,",&xx[i++]);
}
fclose(fp);
return 0;
}

void writeDat(void)
{
FILE *fp;
fp=fopen("OUT.DAT","w");
fprintf(fp,"%d\n%d\n%6.2f\n",totNum,totCnt,totPjz);
fclose(fp);
}

[此贴子已经被作者于2007-9-21 21:59:16编辑过]

搜索更多相关主题的帖子: include double 平均值 正整数 
2007-09-21 21:45
zwlcdh
Rank: 1
等 级:新手上路
帖 子:83
专家分:0
注 册:2007-2-8
得分:0 
很想弄清楚啊!!!救救命啊!明天考试了!!
2007-09-21 21:50
zwlcdh
Rank: 1
等 级:新手上路
帖 子:83
专家分:0
注 册:2007-2-8
得分:0 
我等的好辛苦!
2007-09-21 21:57



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-171944-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 1.741232 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved