In a few places in lab 3 I referred to the mod (or modulus) function. This was and is correct. However, I believe that in speaking to one or two students, I said that the mod function is simply % in C. This is wrong. For positive integers a and b, a%b is indeed a mod b. Also for positive b, 0%b is indeed 0 mod b (i.e. is 0). However for other cases a%b is implementation dependent (it depends on how integer division is defined for that implementation). It is better to think of a%b as the remainder function. In particular (-1)%10 is -1; whereas -1 mod 10 is 9. The solution for lab3 is to write your own mod function. As penance, I have written one and appended it below together with a test program. Also included is the output when run on my computer. If this gives different answers on omicron or acf5, let me know right away. allan gottlieb PS. My solution is quite inefficient; my goal was simplicity. I am assuming b>0 since a mod b in math is only defined for positive integers b. In lab 3, b is positive. PPS. Since I use % in my solution, it is possible that some machine may have a sufficiently wierd integer division that my solution fails. But I don't think acf5, or omicron are this wierd. A safer (but much slower) mod(a,b) would be to start with a and keep adding or subtracting b until the result satisfies 0 <= result < b which is a proper definition of ``modulo b'' ============================ CODE ============================ main () { int a, b; int mod(int a, int b); b = 10; for (a=-20; a<30; a++) printf ("%d mod %d is %d\n", a, b, mod(a,b)); } int mod (int a, int b) { return ((a%b)+b)%b; } ========================== OUTPUT ============================== -20 mod 10 is 0 -19 mod 10 is 1 -18 mod 10 is 2 -17 mod 10 is 3 -16 mod 10 is 4 -15 mod 10 is 5 -14 mod 10 is 6 -13 mod 10 is 7 -12 mod 10 is 8 -11 mod 10 is 9 -10 mod 10 is 0 -9 mod 10 is 1 -8 mod 10 is 2 -7 mod 10 is 3 -6 mod 10 is 4 -5 mod 10 is 5 -4 mod 10 is 6 -3 mod 10 is 7 -2 mod 10 is 8 -1 mod 10 is 9 0 mod 10 is 0 1 mod 10 is 1 2 mod 10 is 2 3 mod 10 is 3 4 mod 10 is 4 5 mod 10 is 5 6 mod 10 is 6 7 mod 10 is 7 8 mod 10 is 8 9 mod 10 is 9 10 mod 10 is 0 11 mod 10 is 1 12 mod 10 is 2 13 mod 10 is 3 14 mod 10 is 4 15 mod 10 is 5 16 mod 10 is 6 17 mod 10 is 7 18 mod 10 is 8 19 mod 10 is 9 20 mod 10 is 0 21 mod 10 is 1 22 mod 10 is 2 23 mod 10 is 3 24 mod 10 is 4 25 mod 10 is 5 26 mod 10 is 6 27 mod 10 is 7 28 mod 10 is 8 29 mod 10 is 9