如何定义一个接收三个参数的函数,函数体内,返回三个参数的中的最大

2025-06-20 14:59:07
推荐回答(3个)
回答1:

#include
int main()
{
int max(int x,int y,int z);
int a,b,c,sum;
scanf("%d,%d,%d",&a,&b,&c);
sum=max(a,b,c);
printf("max=%d\n",sum);
return 0;
}
int max(int x,int y,int z)
{
int m;
if(x>y) m=x;
else m=y;
if(m>z)m=m;
else m=z;
return(m);
}
问题完美解决,手打,求采纳

回答2:

polly@nowthen:~/test$ cat test.c
#include 

static int max(const int, const int, const int);

int main(void)
{
    int a = 3, b = 0, c = -4;
    int m = max(a, b, c);
    
    printf("max of three is %d\n", m);

    return 0;
}

static int max(const int a, const int b, const int c)
{
    return a>b?a>c?a:c:b>c?b:c;
}
polly@nowthen:~/test$ gcc -Wall test.c -o liu
polly@nowthen:~/test$ ./liu
max of three is 3

回答3:


如图