# modulus operator / '%' question

This is a discussion on modulus operator / '%' question within the C Programming forums, part of the General Programming Boards category; Gosh this is such a simple question but dont quite understand the logic. I understand that the modulus operator is ...

1. ## modulus operator / '%' question

Gosh this is such a simple question but dont quite understand the logic. I understand that the modulus operator is represented by '%'. And I understand that the expression x % y produces the remainder when x is divided by y.

So when I divide 74 by 5 the answer is 14.8 . So I thought I should see the answer 8 but instead I see 4. Somebody please explain to me why there is a 4 instead of 8?

[output]

4

[/output]

Code:
```#include <stdio.h>

main()
{
int it;
it = 74 % 5;

printf("%d\n", it);

}```

2. The % operator is defined as the integer remainder (modulus) of integer division.

If you have integers A and B, where C = int(A / B), you can see the remainder, R, as being the result of the expression R = A - (B * C).

What you were expecting was not the remainder, but the fractional part of a floating point result of a division between two whole numbers. That's not what % gives you.

3. Because modulus is the remainder of division, not a fraction.
But 0.8 is also 4 / 5

modulus = x - ( (x / y) * y ), when performed in integer arithmetic.

4. (a/b)*b + a % b = a
Or with decimals
14.8 is equal to 14 and eight tenths, eight is not the remainder of anything.
Eight tenths is equal to 4/5, that is the remander(4 or 74 % 5) divided by 5.
For integers divided by a power of 10 the numbers after the decimal point are the remainder
74 / 10 = 7.4
74 % 10 = 4

5. got it - thank you.