Determining if a number is either a multiple of ten or within a particular set of ranges

后端 未结 13 1474
Happy的楠姐
Happy的楠姐 2021-01-31 07:01

I have a few loops that I need in my program. I can write out the pseudo code, but I\'m not entirely sure how to write them logically.

I need -

if (num is          


        
13条回答
  •  暖寄归人
    2021-01-31 07:22

    If you are using GCC or any compiler that supports case ranges you can do this, but your code will not be portable.

    switch(num)
    {
    case 11 ... 20:
    case 31 ... 40:
    case 51 ... 60:
    case 71 ... 80:
    case 91 ... 100:
        // Do something
        break;
    default:
        // Do something else
        break;
    }
    

提交回复
热议问题