参考:https://blog.csdn.net/qq_43709590/article/details/115015302
如果对你有帮助,可以点击我这个回答右上方的【采纳】按钮,给我个采纳吗,谢谢
假设数据文件名为data.txt,每行记录一条数据,数据为浮点数
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
void main()
{
FILE *fp = NULL;
if(fp = fopen("data.txt","r") == NULL)
{
printf("\nerror on open data.txt file!");
exit(1);
}
float data[1000];
float count = 0;
int n = 0;
char buf[100] = {0};
while(!feof(fp))
{
fgets(buf,100,fp);
data[n++] = atof(buf);
count += data[n-1];
}
fclose(fp);
float avg = count/n;
for(int i=0;i<n;i++)
{
if(fabs(data[i]-avg) < 0.5)
printf("%f ",data[i]);
}
}
您好,我是有问必答小助手,您的问题已经有小伙伴解答了,您看下是否解决,可以追评进行沟通哦~
如果有您比较满意的答案 / 帮您提供解决思路的答案,可以点击【采纳】按钮,给回答的小伙伴一些鼓励哦~~
ps: 问答会员年卡【8折】购 ,限时加赠IT实体书,即可 享受50次 有问必答服务,了解详情>>>https://t.csdnimg.cn/RW5m