How can I repeat a number cycle using mod operator?

I have to loop through 1 <= i <= 20 and every time I mod any i, I want to get a value between 1,2,3. Sorry I have not found any useful resources online. That's why I posted it here. Thanks in advance.

1 answer

  • answered 2022-01-13 05:06 Nathan Pierson

    In C++ the % sign acts as the remainder operator.

    If you do

    i % 3;
    

    The possible values are 0, 1, and 2.

    Using that as a starting point, we can shift by 1:

    (i % 3) + 1;
    

    The possible values are now 1, 2, and 3.

How many English words
do you know?
Test your English vocabulary size, and measure
how many words do you know
Online Test
Powered by Examplum