+ 4
would somebody like to explain how modulo(%) operator works -7%3 = 1, 7%-3 = -2 , negative numbers?
Please give intuitive explanation and not algorithm to calculate it (I am weak at math )
5 Réponses
+ 4
Thanks a lot
+ 3
% gives you the remainder from division. So 7%2 will return 1 because 2 goes into 7, 3 times (6) with 1 left over.
+ 3
Some differences exist between simply getting a remainder of a division and the actual modulus.
Can't really come up with an "intuitive" explanation (not to say there isn't one, but) - You want to understand how it works that way, that directly translates to "the algorithm behind it", and yet you don't want algorithms, so I'm not sure how to approach this. This thread should give a good overview of the topic though.
https://www.sololearn.com/Discuss/989220/?ref=app
+ 3
In computing, the modulo operation finds the remainder after division of one number by another (sometimes called modulus).
Given two positive numbers, a (the dividend) and n (the divisor), a modulo n (abbreviated as a mod n) is the remainder of the Euclidean division of a by n. For example, the expression "5 mod 2" would evaluate to 1 because 5 divided by 2 leaves a quotient of 2 and a remainder of 1, while "9 mod 3" would evaluate to 0 because the division of 9 by 3 has a quotient of 3 and leaves a remainder of 0; there is nothing to subtract from 9 after multiplying 3 times 3. (Doing the division with a calculator will not show the result referred to here by this operation; the quotient will be expressed as a decimal fraction.)
In this example, -7 / 3 => 3 × 2=6, 7-6 = 1 but -7 + 6 = -1.
+ 1
Kindly read post properly
Thanks for answering anyway