/* 没有试运行,应该是可以的 */
#include
int main() {
int n;
while (scanf("%d", &n) == 1) {
if (n == 0)
break;
int sum = 0;
for (int i = 0; i < n; ++i) {
int tmp;
scanf("%d", &tmp);
sum += tmp;
}
printf("average = %lf\n", (double)sum/n);
}
return 0;
}
#include
int main(){
for(int n;scanf("%d",&n);){
int sum=0,temp;
for(int i=1;i<=n;i++){
scanf("%d",&temp);
sum+=temp;
}
printf("%.3f\n\n",float(sum)/n);
}
}
本结果保留三位小数 可自行调整
#include
main( )
{
int a,sum,b;
float avg;
printf("how many numbers :");
scanf("%d",&a);
for(int i=1;i<=a;b=0)
{
printf("input a integer:");
scanf("%d",&b);
sum+=b;
i++;
}
printf("sum=%d",sum);
avg=sum/a;
printf("avg=%.2f\n",avg);
}