c语言case小于,大于和小于switch语句C

我正在尝试编写一个有很多比较的代码

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

following output:

x greater than or equal to 1000 print “hugely positive”

x from 999 to 100 (including 100) print “very positive”

x between 100 and 0 print “positive”

x exactly 0 print “zero”

x between 0 and -100 print “negative”

x from -100 to -999 (including -100) print “very negative”

x less than or equal to -1000 print “hugely negative”

Thus -10 would print “negative”, -100 “very negative” and 458 “very positive”.

然后我尝试使用开关解决它,但它不起作用,我是否必须使用if语句解决它或有一个方法来解决它使用开关?

#include

int main(void)

{

int a=0;

printf("please enter a number : \n");

scanf("%i",&a);

switch(a)

{

case (a>1000):

printf("hugely positive");

break;

case (a>=100 && a<999):

printf("very positive");

break;

case (a>=0 && a<100):

printf("positive");

break;

case 0:

printf("zero");

break;

case (a>-100 && a<0):

printf("negative");

break;

case (a-999):

printf("very negative");

break;

case (a<=-1000):

printf("hugely negative");

break;

return 0;

}

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值