输入三个实型数据,求最大值比平均数大多少。 定义和调用函数Max(a,b,c)用来求最大值,Avg(a,b,c)用来求平均数。
#include <stdio.h>
double Max(double a,double b,double c);
double Avg(double a,double b,double c);
int main() {
double a,b,c;
printf("输入三个数,空格隔开:");
scanf("%lf%lf%lf",&a,&b,&c);
printf("最大值比平均值大%lf\n",Max(a,b,c) - Avg(a,b,c));
return 0;
}
double Max(double a,double b,double c) {
double max = a;
if(max < b) max = b;
if(max < c) max = c;
return max;
}
double Avg(double a,double b,double c) {
return (a + b + c)/3.0;
}
Max函数求三个数最大的值,Avg是求三个数平均值值,在主函数中分别调用函数然后得到结果
#include <stdio.h>
double Max(double a,double b,double c)
{
double max = a;
if(b >max)
max = b;
if(c > max)
max =c;
return max;
}
double Avg(double a,double b,double c)
{
return (a+b+c)/3;
};
void main()
{
double a,b,c;
scanf("%lf %lf %lf",&a,&b,&c);
double max = Max(a,b,c);
double avg = Avg(a,b,c);
printf("max=%lf;avg = %lf; max-avg=%lf\n",max,avg,max-avg);
getchar();
getchar();
}
您好,我是有问必答小助手,您的问题已经有小伙伴解答了,您看下是否解决,可以追评进行沟通哦~
如果有您比较满意的答案 / 帮您提供解决思路的答案,可以点击【采纳】按钮,给回答的小伙伴一些鼓励哦~~
ps:问答VIP仅需29元,即可享受5次/月 有问必答服务,了解详情>>>https://vip.csdn.net/askvip?utm_source=1146287632