-5

4 つの地域があります。a b c d

これらの領域に数字を入れたいと思います。

switch ステートメントのみを使用してこれを行う方法:

 the number divisible by 10 and divisible by 7 ın region a
 the number divisible by 10 but not divisible by 7 ın region b
 the number not divisible by 10 but divisible by 7 ın region c
 the number not divisible by 10 and divisible by 7 ın region d

たとえば、次の場合:

input 770 out put is a

input 200 output b

input 154 output c
4

3 に答える 3

6

ただし、これがあなたが求めているものかどうかはわかりませんが、次のようなものが機能する可能性があります。

switch ((number % 7 == 0) * 2 + (number % 10 == 0))
{
case 0:
  puts("d");
  break;
case 1:
  puts("b");
  break;
case 2:
  puts("c");
  break;
case 3:
  puts("a");
  break;
}
于 2013-04-03T10:20:11.137 に答える