我从我写的程序中得到了一些错误。我正在尝试制作一个程序,可以找到数据中的项目数,数据中的高值和低值,均值,中位数,模式,方差和标准差。
我得到的错误是错误:从(路径)filename.c引用的未解析的外部'_mean'
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
void readData(float[],int count);
float dataMean(float[],int count);
float dataSd(float[],int count);
float dataMin(float[],int count);
float dataMax(float[],int count);
float dataMedian(float[],int count);
int main()
{
float data[200];
int choice,count=0,i;
do
{
printf("*****************************************************************\n");
printf("* This program will perform the following: *\n");
printf("* 1.Enter Data *\n");
printf("* 2.Display the data and the following statistics: *\n");
printf("* The number of date item, the high and low values in the *\n");
printf("* data, the mean, median, mode, variance and standard deviation.*\n");
printf("* 3.Quit the program *\n");
printf("*****************************************************************\n");
printf("\n\nYour Choice: ");
scanf("%d",&choice);
printf("Enter one data item after each prompt.\n");
printf("Enter -1 with when you are done with data input.\n\n");
switch(choice)
{
case 1:
readData(data,count);
break;
case 2:
printf("\nGiven data: \n");
printf("%.2f ",data[i]);
printf("\n\nTotal no of data items: %d",count);
printf("\nHighest value in the data: %.2f",dataMax(data,count));
printf("\nLowest value in the data: %.2f",dataMin(data,count));
printf("\nMean: %.2f",dataMean(data,count));
printf("\nMedian: %.2f",dataMedian(data,count));
printf("\nStandard Deviation: %.2f",dataSd(data,count));
printf("\nVariance: %.2f\n\n",pow((dataSd(data,count)),2));
break;
case 3:
exit(0);
}
}while(1);
getchar();
return 0;
}
void readData(float data[],int count)
{
int value = 0;
int item[200];
printf("Item #%d:\t",value++);
scanf("%f",&item);
while((item) != EOF)
{
printf("Item #%d:\t",value++);
scanf("%f",&item);
}
return *item;
}
float dataMean(float *data,int count)
{
int i;
float mean=0.0;
for(i=0;i<count;i++)
{
mean+=data[i];
}
return mean/count;
}
float dataSd(float data[],int count)
{
float avg=dataMean(data,count);
float SD =0.0;
int i;
for(i=0;i<count;i++)
{
SD+= pow((data[i]-avg),2);
}
return sqrt(SD/count);
}
float dataMax(float data[],int count)
{
int i=0;
float max=data[0];
for(i=0;i<count;i++)
if(max<data[i])
max=data[i];
return max;
}
float dataMin(float data[],int count)
{
int i=1;
float min=data[0];
for(i =0;i<count;i++)
if(min>data[i])
min=data[i];
return min;
}
float dataMedian(float data[],int count)
{
int i,j;
float tmp;
for(i=0;i<count-1;i++)
for( j=i+1;j<count;j++)
if(data[i]>data[j])
{
tmp=data[i];
data[i]=data[j];
data[j]=tmp;
}
if(count%2==0)
return (data[count/2-1]+data[count/2])/2;
else
return data[count/2];
}
答案 0 :(得分:1)
math.h中没有平均值(...)
float dataSd(float data[],int count)
{
float avg=mean(data,count);
float SD =0.0;
int i;
for(i=0;i<count;i++)
{
SD+= pow((data[i]-avg),2);
}
return sqrt(SD/count);
}
答案 1 :(得分:1)
mean(data,count);
链接器告诉您,它无法找到mean()
函数。没有这样的功能。