Larger than and less than in C switch statement

后端 未结 7 838
闹比i
闹比i 2020-12-29 04:57

I\'m trying to write a code that has a lot of comparison

Write a program in “QUANT.C” which “quantifies” numbers. Read an integer “x” and test it, pro

7条回答
  •  一向
    一向 (楼主)
    2020-12-29 05:13

    Why do you have a preference to use switch?

    I'm asking because this sounds awfully like a 'homework question'. A compiler should deal with if/else construct just as efficiently as a switch (even if you weren't dealing with ranges).

    Switch can't handle ranges as you have shown, but you could find a way to include switch by categorising the input first (using if/else) then using a switch statement to output the answer.

提交回复
热议问题