# Modulus division

This is a discussion on Modulus division within the C Programming forums, part of the General Programming Boards category; I have been doing lots of exercises on the book that I have then I went to encryption. This is ...

1. ## Modulus division

I have been doing lots of exercises on the book that I have then I went to encryption. This is just a very simple encryption on the book. It says that you have to enter only 4 digit number and each digit must be encrypted using the following:

digit + 7 % 10, swap the first digit to the third digit, swap the 2nd digit to the fourth digit. Provide an option to decrypt the encrypted value as well.

I wrote down the solution before coding it.

Ex:

Code:
```I input 1234

1 + 7  = 8
2 + 7  = 9
3 + 7  = 10
4 + 7  = 11

After getting the sum of the each digit + 7 I did:

8 % 10 = 2   //this should be 2, if not, 0 - but the compiler displays 8
9 % 10 = 1   //this should be 1, if not 0 - but the compiler displays 9
10 % 10 = 0 //expected value
11 % 10 = 1 //expected value as well```

2. The modulo operator gives you the remainder from a division operation. 8 / 10 is 0 with a remainder of 8 which is what 8 % 10 gives you.

3. >> 8 % 10 = 2

This is a very common mistake, and in fact I made it just the other day! But 8 / 10 == 0 R 8, similarly, 18 / 10 == 1 R 8. Put another way 0 * 10 + 8 == 8.

4. I never thought of that, so simple, hehehehe..

5. Any number modulo a number greater that itself will return the original number.

2 % 10 = 2

8 % 10 = 8

However, 10 % 8 = 2, which is what I believe you were expecting the answer to be.