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

后端 未结 13 1446
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:29

    For the first one:

    if (x % 10 == 0)
    

    will apply to:

    10, 20, 30, .. 100 .. 1000 ...
    

    For the second one:

    if (((x-1) / 10) % 2 == 1)
    

    will apply for:

    11-20, 31-40, 51-60, ..
    

    We basically first do x-1 to get:

    10-19, 30-39, 50-59, ..
    

    Then we divide them by 10 to get:

    1, 3, 5, ..
    

    So we check if this result is odd.

提交回复
热议问题