gpt4 book ai didi

c - 开关盒(C 型)

转载 作者:行者123 更新时间:2023-11-30 21:14:30 27 4
gpt4 key购买 nike

我们有 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

最佳答案

这样的东西可能会起作用,但不确定这是否是您所要求的:

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;
}

关于c - 开关盒(C 型),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15784609/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com