我被分配设置一个带点的数组.我被告知获得最大值,平均值,并且在同一个数组中,如果数组中的任何点是平均值的两倍,我应该cout是"异常值".到目前为止,我已经获得了数组中的平均数和最大数.但我无法将程序设置cout为异常值.相反,它给了我平均值的倍数.这是程序;
int main()
{
const int max = 10;
int ary[max]={4, 32, 9, 7, 14, 12, 13, 17, 19, 18};
int i,maxv;
double out,sum=0;
double av;
maxv= ary[0];
for(i=0; i<max; i++)
{
if(maxv<ary[i])
maxv= ary[i];
}
cout<<"maximum value: "<<maxv<<endl;
for(i=0; i<max; i++)
{
sum = sum + ary[i];
av = sum / max;
}
cout<<"average: "<<av<<endl;
out = av * 2;
if(ary[i]>out)
{
cout<<"outlier: "<<maxv<<endl;
}
else
{
cout<<"ok"<<endl;
}
return 0;
}
Run Code Online (Sandbox Code Playgroud) c++ ×1