+ 11
Why does this problem print 4?
int a = 9%5%5;
9 Respuestas
+ 13
The answer is here with explaination
To find 4 mod 5 using the Modulus Method, we first find the highest multiple of the Divisor (5) that is equal to or less than the Dividend (4).
Then, we subtract the highest Divisor multiple from the Dividend to get the answer to 4 modulus 5 (4 mod 5):
Multiples of 5 are 0, 5, 10, 15, etc. and the highest multiple of 5 equal to or less than 4 is 0. Therefore, to get the answer:
4 - 0 = 4
+ 9
Sorry for giving you wrong answer.
+ 9
9%5=4
4%5=4
So the output is 4
+ 5
The roll of % is remainder:
It divides the number until it can't divide anymore so if you try to divide 4 by 5 you can't so it I'll return 4
+ 3
(Natural number is any non-negative whole number: 0, 1, 2,...)
9%5:
Unlimitely subtracts/adds 5 from 9 until 9 is the smallest possible natural number.
9-5 = 4
4 is the smalles possible natural number, because if you subtracted 5 again:
4-5 = -1
-1 is not a natural number.
When 9%5 = 4: 9%5%5 = 4%5:
4 is already the smallest possible natural number, when 4 got unlimitely added/subtracted 5, then the result is 4.
x%y%y = x%y
X%Y:
Unlimitely subtracts/adds Y from X until X is the smallest possible natural number.
+ 2
9%5=4%5=4
+ 2
Eliya Ben Baruch 4%5=4 How?
Rest -> 0
+ 1
Rohit Gupta are you sure that 4%5 = 0?
+ 1
'%' is modulus. These operators gives the remainder of any division. In above example, 9%5%5, the first part, i.e. 9%5 gives remainder 4. In the next part, 4%5 will give you answer 4 once more. Thus, the answer is 4.
Hope it helps 😊