V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
zhiml0ve
V2EX  ›  问与答

C 语言比较三个数字大小最简洁的写法是怎样?

  •  
  •   zhiml0ve · Oct 27, 2015 · 2901 views
    This topic created in 3835 days ago, the information mentioned may be changed or developed.
    能想到的是引入一个 t 变量,
    如果 a<b, 调换 ab 

    如果 a<c, 调换 ac
    最后比较 bc 
得出结果
    4 replies    2015-10-28 00:08:39 +08:00
    hx1997
        1
    hx1997  
       Oct 27, 2015
    所以 t 变量是干啥的?交换?

    难道不应该是

    t = a;
    if (t < b) t = b;
    if (t < c) t = c;

    吗?
    wsy2220
        2
    wsy2220  
       Oct 27, 2015 via Android
    怎么清楚怎么写,代码是给人看的。
    精简的事情编译器比你专业
    hx1997
        3
    hx1997  
       Oct 27, 2015
    啊,是我没看仔细。我以为是找最大的数来着。

    那我觉得可能就是问题里那种写法了吧,如果说最简洁的。
    zhiml0ve
        4
    zhiml0ve  
    OP
       Oct 28, 2015
    @hx1997 哈哈,谢谢回答
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1009 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 34ms · UTC 22:15 · PVG 06:15 · LAX 15:15 · JFK 18:15
    ♥ Do have faith in what you're doing.