发新话题
打印

一道C语言题.

一道C语言题.

  任意三个实数,请分别编写d_max();d_min();d_aver()三个函数来求解这三个实数的最大值,最小值和平均值,要求在主函数中执行输入三个实型数据和输出计算结果的操作过程.
我将采纳第一个回答并正确的.
相关主题

TOP

  #include <stdio.h>

float d_max(float x, float y, float z);
float d_min(float x, float y, float z);
float d_aver(float x, float y, float z);

void main()
{
float x, y, z;
printf("please input three numbers:");
scanf("%f%f%f", &x, &y, &z);
printf("max number is:%f\n", d_max(x, y, z));
printf("min number is:%f\n", d_min(x, y, z));
printf("average is:%f\n", d_aver(x, y, z));
}

float d_max(float x, float y, float z)
{
float t;
if (x < y) t = y;
else t = x;
if (t < z) t = z;
return t;
}

float d_min(float x, float y, float z)
{
float t;
if (x > y) t = y;
else t = x;
if (t > z) t = z;
return t;
}

float d_aver(float x, float y, float z)
{
return ((x + y + z) / 3);
}

TOP

发新话题