首页 > 编程语言 > 详细

c语言 8-2

时间:2021-05-21 23:50:52      阅读:22      评论:0      收藏:0      [点我收藏+]

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

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

原文:https://www.cnblogs.com/liujiaxin2018/p/14797654.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!