定义函数式宏,返回两个数中的最大值。

1、

#include <stdio.h>

#define max(x, y) ((x > y) ? (x) : (y))

int main(void)
{
    int a, b, c, d;
    puts("please input four integers.");
    printf("a = "); scanf("%d", &a);
    printf("b = "); scanf("%d", &b);
    printf("c = "); scanf("%d", &c);
    printf("d = "); scanf("%d", &d);
    printf("int method 1    %d\n", max(max(a,b),max(c,d)));
    printf("int method 2    %d\n\n\n", max(max(max(a,b),c),d));
    
    double i, j, m, n;
    puts("please input four real numbers.");
    printf("i = "); scanf("%lf", &i);
    printf("j = "); scanf("%lf", &j);
    printf("m = "); scanf("%lf", &m);
    printf("n = "); scanf("%lf", &n);
    printf("double method 1    %f\n", max(max(i,j), max(m,n)));
    printf("double method 2    %f\n", max(max(max(i,j),m),n));
    
    return 0;
}

c语言 8-2_C语言