#include
#include
int main(){
int i = 0;
int a[20];
int avi = 0;
int count = 0;
for(i=0;i<20;++i){
printf("please input 20 numbers:");
scanf("%d",&a[i]);
}
for(i=0;i<20;++i){
count += a[i];
}
avi = count/20;
for(i=0;i<20;++i){
printf("%d 和平均值%d的绝对值为:%d\n",a[i],avi,abs(avi - c[i]));
}
return 0;
}
用for循环输入,每次输入用和变量磊加,输入完成后求平均值,输出时当前数减去平均值(结果判断下负数)
这里用两个for循环
#include
void main()
{
int i,a[20];
double average,sum=0;
for(i=0;i<20;i++)
{
scanf("%d",&a[i]);
sum=sum+a[i];
}
average=sum/20;
for(i=0;i<20;i++)
{
printf("%lf ",fabs(a[i]-average));
}
}