c语言题目 输入5个分数(实数),求其总分,平均分,最高分,最低分。
发布网友
发布时间:2022-04-23 21:04
我来回答
共5个回答
热心网友
时间:2023-10-09 15:51
#include<stdio.h>
#include<algorithm>
using namespace std;
int main()
{
double s[5];
//printf("请输入5个数:\n");
scanf("%lf%lf%lf%lf%lf",&s[0],&s[1],&s[2],&s[3],&s[4]);
int n=sizeof(s)/sizeof(s[0]);
double sum=0,ave=0;
for(int i=0;i<n;i++)
sum+=s[i] ;
ave=sum/n;
sort(s,s+n);
printf("%5.1lf %5.1lf %5.1lf %5.1lf",sum,ave,s[4],s[0]);
return 0;
}
热心网友
时间:2023-10-09 15:52
# include "stdio.h"
int main()
{
int n=5,i=0;
float sum,max,ave,min;
sum=max=min=ave=0;
float a[5];
for(i;i<5;i++)
{
scanf("%f",&a[i]);
a[i]=0.1*(int)(a[i]*10+0.5);
sum=sum+a[i];
if(i==0){
max=min=a[i];
}
if(a[i]>min){
max=a[i];
}
if(a[i]<min)
{
min=a[i];
}
}
ave=sum/5;
printf("max=%.1f\t",max);
printf("min=%.1f\t",min);
printf("sum=%.1f\t",sum);
printf("ave=%.1f\t",ave);
}
热心网友
时间:2023-10-09 15:52
int main(){float a[5]={0};//定义数组,存放将要输入的5个数字float sum=0,min,max,mean=0;scanf("%f%f%f%f%f",&a[0],&a[1],&a[2],&a[3],&a[4]);min = a[1];max = a[1];for(int i=0;i<5;++i){ if(min>a[i]) min = a[i]; if(max<a[i]) max = a[i]; sum = sum + a[i];}mean = sum / 5;printf("%f,%f,%f,%f",sum,mean,max,min);return 0;}
求采纳为满意回答。
热心网友
时间:2023-10-09 15:53
#include <stdio.h>
int main()
{
double dbArray[5] = {0.0};
double dbMix =0.0,dbMin = 0.0;
double dbSum =0.0;
int i = 0;
while( i < 5 && EOF != scanf("%f",dbArray+i++));
dbSum = dbMix = dbMin = dbArray[0];
i = 1;
while(i < 5)
{
if (dbMix < dbArray[i])
{
dbMix = dbArray[i];
}
if (dbMin > dbArray[i])
{
dbMin = dbArray[i];
}
dbSum += dbArray[i];
}
printf("total(%5.1f),avg(%5.1f),Mix(%5.1f),Min(%5.1f)\n",
dbSum,dbSum / (double)5,dbMix,dbMin);
return 0;
}
热心网友
时间:2023-10-09 15:53
#include <stdio.h>
int main()
{
double num[5], sum=0, average, max, min;
for (int i = 0; i < 5; ++i)
scanf("%lf", num + i);
max = min = num[0];
sum = 0;
for (int i = 0; i < 5; ++i)
{
sum += num[i];
if (num[i] > max) max = num[i];
if (num[i] < min) min = num[i];
}
average = sum / 5.0;
printf("%-5.1f %-5.1f %-5.1f %-5.1f\n", sum, average, max, min);
return 0;
}
刚才有个错误,现在好了