C语言中用函数比较三个数的大小,并输出最大值,最小值以及最大值与最小值的差值?

2025-01-29 16:07:40
推荐回答(3个)
回答1:

#include 
#include "math.h"
void func(int* in,int* ou)
{
    int mi,ma;
    mi=(in[0]>in[1]?in[1]:in[0]);
    mi=(mi>in[2]?in[2]:mi);
    ma=(in[0]>in[1]?in[0]:in[1]);
    ma=(ma    ou[0]=mi;//最小值
    ou[1]=ma;//最大值
    ou[2]=ma-mi;//差
}
int main()
{
    int a[3]={1,2,3},b[3];
    func(a,b);
    cout<}

回答2:

#include
#define MAX(A,B) ( (A) >= (B) ? (A) : (B) )
#define MIN(A,B) ( (A) <= (B) ? (A) : (B) )
int main()
{
    float a,b,c,max,min;
    printf("Input 3 integers\n");
    scanf("%f%f%f",&a,&b,&c);
    max = MAX(MAX(a,b),c);
    min = MIN(MIN(a,b),c);
    printf("MAX:%g\n",max);
    printf("MIN:%g\n",min);
    printf("D-value:%g\n",max-min);
    return 0;
}

回答3:

# include
void main()
{
int max(int x,int y,int z);
int min(int x,int y,int z);
int a,b,c,ma,mi,diff;
scanf("%d,%d,%d",&a,&b,&c);
ma=max(a,b,c);
mi=min(a,b,c);
diff=ma-mi;
printf("max = %d\nmin = %d\ndiff = %d\n",ma,mi,diff);
}
int max(int x,int y,int z)
{
int m,n;
if(x>y) m = x;
else m = y;
if(m>z) n = m;
else n = z;
return(n);
}
int min(int x,int y,int z)
{
int m,n;
if(x>y) m = y;
else m = x;
if(m>z) n = z;
else n = m;
return(n);
}