Zzzp
V2EX  ›  问与答

用 switch 比较两个数的大小

  •  
  •   Zzzp · Jul 21, 2018 · 3544 views
    This topic created in 2858 days ago, the information mentioned may be changed or developed.

    大佬们好,小白想问下能不能用 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  
       Jul 21, 2018 via iPhone
    switch(a>b)
    case true
    case false
    C02TobNClov1Dz56
        2
    C02TobNClov1Dz56  
       Jul 22, 2018
    1 楼说得很明白了,switch 里放变量,case 是变量的值。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   4954 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 30ms · UTC 01:11 · PVG 09:11 · LAX 18:11 · JFK 21:11
    ♥ Do have faith in what you're doing.