why is it that (smaller integer) % (bigger integer) = smaller integer e.g ( 1%2 = 1 )

58 Views Asked by At

By % I mean modulus it divides two numbers and puts out their remainder its an operator in C and C++ ( computer language ) so main question is isn't the remainder of 1 divided by 2 suppose to be zero ??? what I get is 1 mod(%) 2 = 1 ??

3

There are 3 best solutions below

0
On BEST ANSWER

The mod operator gives the value of the remainder i.e a%b returns the remainder obtained when a is divided by b . So 1%2 gives value of the remainder 1 i.e 1= 2×0+1, so the remainder is 1. We are operating inside the set of integers so 2 doesnt divide 1 n so the remainder can never be 0.

0
On

When you divide $1$ by $2$ in the naturals, you get a quotient of $0$ and a remainder of $1$. The mod operator returns the remainder, so $1 \%2=1$. If you do $1/2$ you get $0$ because that returns the quotient. For a larger example, $13/5=2, 13 \% 5=3$ because $13=2 \cdot 5 + 3$

0
On

Whenever $0\le a<b$, $a\text{ div }b=0$ and $a\bmod b=a$.

The identity

$$(a\text{ div }b)\cdot b+(a\bmod b)=a$$ is always true.