C语言调用函数求最大值

题目描述:编写一个带参数的宏MAX,实现求两数中的较大值。在main函数中,输
入3个整数x、y和z,利用宏MAX求解并输出这三个数的最大值。
如图所示

img

用三目运算符定义宏就行了

#include <stdio.h>
#define MAX(a,b) (a>b?a:b)

int main()
{
    int x,y,z;
    scanf("%d%d%d",&x,&y,&z);
    printf("%d",MAX(MAX(x,y),z));
    return 0;
} 

#include <stdio.h>
#include <stdlib.h>
#define MAX(X,Y) ((X)>(Y)?(X):(Y))
int main()
{
    int a,b,c;
    scanf("%d%d%d", &a, &b,&c);
    int max = MAX(a, b);
    max=MAX(max,c);
    printf("%d", max);
    return 0;
}

代码如下,有帮助的话采纳一下哦!
两个数:

#include <stdio.h>
#define MAX(x,y) x>y?x:y
int main()
{
    int maxVal = MAX(2,5);
    printf("maxVal is %d.\n", maxVal);    
    return 0;
}

三个数:

#include<stdio.h>
#define Max(a, b, c) (a) > (b)? ((a) > (c)? (a) : (c)) : ((b) > (c)? (b):(c))
int main()
{
    int a = 0, b = 0, c = 0, _max = 0;
    printf("Input three number:");
    scanf("%d%d%d",&a,&b,&c);
    _max = Max(a, b, c);
    printf("Output the max number:%d",_max);
    return 0;
}
您好,我是有问必答小助手,您的问题已经有小伙伴帮您解答,感谢您对有问必答的支持与关注!
PS:问答VIP年卡 【限时加赠:IT技术图书免费领】,了解详情>>> https://vip.csdn.net/askvip?utm_source=1146287632