V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
Zzzp
V2EX  ›  问与答

用 switch 比较两个数的大小

  •  
  •   Zzzp · 2018-07-21 21:40:02 +08:00 · 2715 次点击
    这是一个创建于 2105 天前的主题,其中的信息可能已经有所发展或是发生改变。

    大佬们好,小白想问下能不能用 switch 比较两个数的大小 #include <stdio.h> int main(void) { int a,b; printf("please input two number:\n"); scanf("%d %d",&a,&b); switch() case a<b: printf("a<b\n"); break; case a>b: printf("a>b\n"); break; case a=b: printf("a=b\n"); break; }

    我不知道 switch 里面的表达式该写什么,还是说我其他地方有问题,还请大佬们帮我指出来,谢谢!

    nethard
        1
    nethard  
       2018-07-21 22:16:30 +08:00 via iPhone
    switch(a>b)
    case true
    case false
    chengyiqun
        2
    chengyiqun  
       2018-07-22 14:49:29 +08:00
    1 楼说得很明白了,switch 里放变量,case 是变量的值。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2902 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 11:24 · PVG 19:24 · LAX 04:24 · JFK 07:24
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.