Skip to main content
1 of 2
gilhad
  • 1.5k
  • 2
  • 11
  • 22

Simply use modulo

#include <stdio.h>

int main(){
   for (int i = -23;i<23;i++) printf("%d    %d\n",i,i%11);
   return 0;
}

all modern C variants should work the same way https://en.wikipedia.org/wiki/Modulo_operation (result have same sign as divident):

-23 -1
-22 0
-21 -10
-20 -9
-19 -8
-18 -7
-17 -6
-16 -5
-15 -4
-14 -3
-13 -2
-12 -1
-11 0
-10 -10
-9  -9
-8  -8
-7  -7
-6  -6
-5  -5
-4  -4
-3  -3
-2  -2
-1  -1
0   0
1   1
2   2
3   3
4   4
5   5
6   6
7   7
8   8
9   9
10  10
11  0
12  1
13  2
14  3
15  4
16  5
17  6
18  7
19  8
20  9
21  10
22  0
gilhad
  • 1.5k
  • 2
  • 11
  • 22