〔C语言〕定义max函数,可以返回3个整数都最大值,在主函数中调用max函数

请问这种的代码怎么写?思路是怎样的?麻烦大家帮我解答一下,谢谢大家

如下:

#include <stdio.h>
int max(int a,int b,int c)
{
    int t;
    //找到a和b中的较大值,并用t记录这个大值
    if(a>b)
        t = a;
    else
        t = b;

    //用t和c进行比较,返回大值
    if(t>c)
        return t;
    else
        return c;
}

int main()
{
    int a,b,c;
    scanf("%d %d %d",&a,&b,&c);
    printf("max=%d",max(a,b,c));
    return 0;
}

简单一点用三目运算符比较

max= a> b? a: b;
max= max>c? max: c;

直接比较某个数是不是大于另两个数