[ZJ]d786: 三、平均值
題目:
http://zerojudge.tw/ShowProblem?problemid=d786
==================================================
#include<stdio.h>
#include<stdlib.h>
#define N 150
int main()
{
int T;
while(scanf("%d",&T)!=EOF)
{
int a=0;
while(a<T)
{
int n=0,x[N]={0};
double avg=0.0;
a++;
scanf("%d",&n);
for(int i=0;i<n;i++)
{
scanf("%d",&x[i]);
avg+=x[i];
}
printf("%.2lf\n",avg/n);
}
}
return 0;
}
http://zerojudge.tw/ShowProblem?problemid=d786
==================================================
#include<stdio.h>
#include<stdlib.h>
#define N 150
int main()
{
int T;
while(scanf("%d",&T)!=EOF)
{
int a=0;
while(a<T)
{
int n=0,x[N]={0};
double avg=0.0;
a++;
scanf("%d",&n);
for(int i=0;i<n;i++)
{
scanf("%d",&x[i]);
avg+=x[i];
}
printf("%.2lf\n",avg/n);
}
}
return 0;
}
留言
張貼留言