用c语言编写程序:求一维数组中的最大值、最小值、平均值、各元素之和。

2025-04-16 03:16:43
推荐回答(1个)
回答1:

#include
main()
{
int i,t;
double score[102],min,max,sum,d;//定义的数组大小和你要输入多少个数对应
(scanf("%d",&i);
d=0;
for(t=0;t {
scanf("%lf",&score[t]);
d=d+score[t];//各项的总和
}
if(i==2)
{
sum=d/2;
}
else
{
min=score[0];
for(t=1;t {
if(min>score[t])
{
min=score[t];//最小值
}
}
max=score[0];
for(t=1;t {
if(max {
max=score[t];//最大值
}
}
sum=(d)/(i);//平均分
}
printf("%lf %lf %lf %lf",max,min,sun,d);

}