zoukankan      html  css  js  c++  java
  • [C]分别用函数和带参的宏,求3个数中的最大值

    //带参宏求3个数的最大值
    #include <stdio.h>
    #define MAX(a, b, c) (a>b?a:b)>c?(a>b?a:b):c
    int main()
    {
        int a, b, c;
        puts("input three numbers, use space to seperate each other:");
        scanf("%d%d%d", &a, &b, &c);
        printf("%d
    ", MAX(a,b,c));
        return 0;
    }
    //用函数求三个数的最大值
    #include <stdio.h>
    int MAX(int a, int b, int c); //函数声明
    int main()
    {
        int a, b, c;
        puts("input three numbers, use space to seperate each other:");
        scanf("%d%d%d", &a, &b, &c);
        printf("%d
    ", MAX(a,b,c));
        return 0;
    }
    
    int MAX(int a, int b, int c)
    {
        int max;
        if (a > b)
            max = a;
        else
            max = b;
        if (c > max)
            max = c;
        return max;
    }
    //以上两个方法合起来,投机取巧地采用函数求三个数的最大值
    #include <stdio.h>
    int MAX(int a, int b, int c); //函数声明
    int main()
    {
        int a, b, c;
        puts("input three numbers, use space to seperate each other:");
        scanf("%d%d%d", &a, &b, &c);
        printf("%d
    ", MAX(a,b,c));
        return 0;
    }
    
    int MAX(int a, int b, int c)
    {
        return (a>b?a:b)>c?(a>b?a:b):c;
    }
  • 相关阅读:
    Spring-Task
    bootstrap table分页(前后端两种方式实现)
    jquery file upload示例
    ajax传递list集合
    cogs 2383. [Hnoi2014]世界树 WD
    cogs 36.求和问题
    bolg
    noip2016
    cogs 1619. [HEOI2012]采花 AC
    leetcode[109]Convert Sorted List to Binary Search Tree
  • 原文地址:https://www.cnblogs.com/profesor/p/12970506.html
Copyright © 2011-2022 走看看