然后这个是我写的代码,为什么不行啊?
#include <iostream>
#include <math.h>
using namespace std;
void statistics(double a[],int n,double *max,double *min,double *avg,double *stdev)
{
int i,d=0,e=0;
for(i=0;a[i]!=-9999;i++)
{
d+=a[i];
}
*avg=d/i;
i=0;
while(a[i]=-9999)
{
*max=*max>a[i]?a[i]:*max;
*min=*min<a[i]?a[i]:*min;
i++;
}
for(i=0;a[i]!=-9999;i++)
e+=pow((a[i]-*avg),2);
*stdev=sqrt(1/i*e);
}
int main()
{
int b,i;
double a[200],c=0;
double *max=&c,*min=&c,*avg=&c,*stdev=&c;
cout<<"请输入数据:";
for(i=0;a[i]!=-9999;i++)
cin>>a[i];
b=i;
statistics(a,b,max,min,avg,stdev);
cout<<" "<<*max<<" "<<*min<<" "<<*avg<<" "<<*stdev;
return 0;
}
#include <iostream>
#include <math.h>
using namespace std;
void statistics(double a[],int n,double *max,double *min,double *avg,double *stdev)
{
int i,d=0,e=0;
for(i=0;a[i]!=-9999;i++)
{
d+=a[i];
}
*avg=d/i;
i=0;
while(a[i]=-9999)
{
*max=*max>a[i]?a[i]:*max;
*min=*min<a[i]?a[i]:*min;
i++;
}
for(i=0;a[i]!=-9999;i++)
e+=pow((a[i]-*avg),2);
*stdev=sqrt(1/i*e);
}
int main()
{
int b,i;
double a[200],c=0;
double *max=&c,*min=&c,*avg=&c,*stdev=&c;
cout<<"请输入数据:";
for(i=0;a[i]!=-9999;i++)
cin>>a[i];
b=i;
statistics(a,b,max,min,avg,stdev);
cout<<" "<<*max<<" "<<*min<<" "<<*avg<<" "<<*stdev;
return 0;
}