白细胞计数题解
【题目要求】求n个样本中平均白细胞数量和对应的误差。
先把n个样本从小到大排个序,然后去掉第1、2数,接着
求出n-2个数的平均值,再计算误差。
include<bits/stdc++.h>
using namespace std;
double n,a[10000000],b=0,c,e=0,s=0;建立双精度浮点数n,数组a,b,c,e,s,其中b、e、s等于0
int main(){
cin>>n;输入n
for(int i=1;i<=n;i++){重复执行n次
cin>>a[i];输入a的第i个数
}
for(int j=1;j<=n;j++){重复执行n次
for(int m=1;m<=n-1;m++){重复执行n-1次
if(a[m]>a[m+1]){如果a的第m个数大于a的第m+1个数
swap(a[m],a[m+1]);那么a的第m个数和a的第m+1个数交换
}
}
}
for(int o=2;o<=n-1;o++){重复执行从2到n-1次
b=b+a[o];b等于b加a的第o个数
}
b=b/(n-2);b等于b除以n减2的差
for(int l=2;l<=n-1;l++){重复执行从2到n-1次
c=fabs(b-a[l]);c等于b减a的第l个数的绝对值
if(c>s){如果c大于s
s=c;那么s=c
}
}
cout<<fixed<<setprecision(2)<<b;保留两位小数输出b
cout<<" ";输出空格
cout<<fixed<<setprecision(2)<<s;保留两位小数输出s
return 0;
}