What's the use of modulo? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

What's the use of modulo?

Like int x = 5; int y = 25; int res = y % x; System.out.println(res) Someone explain?

23rd Sep 2022, 12:43 PM
Elias Ser Frias
Elias Ser Frias - avatar
14 Answers
+ 7
module returns reminder value y % x = 25 % 5 = 0 Because we can divide 25 with 5 If y = 26 then 26 % 5 = 1 because 5 * 5 + 1 = 26
23rd Sep 2022, 1:00 PM
A͢J
A͢J - avatar
+ 7
Think of it like in elementary school maths: If we divide 7 by 2, we get 3 plus a remainder of 1. The modulo operator gives us this remainder.
23rd Sep 2022, 1:08 PM
Lisa
Lisa - avatar
+ 4
Walie Ojwallah 2%5 = 2, not 1
25th Sep 2022, 5:47 AM
Yaroslav Vernigora
Yaroslav Vernigora - avatar
+ 3
The operator of the remainder of the number % (for example: 17 % 3 = 2) 1. Take the nearest number when divided by 3 would be zero. That's apparently 15 2. Subtract 15 from 17 and the result is your answer.
23rd Sep 2022, 1:08 PM
Yaroslav Vernigora
Yaroslav Vernigora - avatar
+ 2
3%8 = ?
23rd Sep 2022, 7:15 PM
Yaroslav Vernigora
Yaroslav Vernigora - avatar
+ 1
Modulo division gives us the ability to determine multiples of let's say 5: 5, 10, 15, 20, 25 ALI Moussa Kadjalla this is not the first time I have come across this answer of yours with the incorrect formula of division modulo. Here is a correct calculation of division modulo: a%b == a-a//b*b
23rd Sep 2022, 4:26 PM
Solo
Solo - avatar
+ 1
Rather than divison (which gives quotient), modulo gives remainder as the ans As 6%5 gives 1(remainder) 8%3 gives 2(remainder
25th Sep 2022, 8:10 AM
Keerti Pandey
+ 1
Like num = int ( input ( "Enter an integer:")) if num % 2 == 0: print ( num,"is EVEN number.") else : print (num,"is ODD number.")
25th Sep 2022, 12:51 PM
10A_ Anurag Singh
0
the operation modulo(%) finds the rest or the rest signed after the division of a number by another (called the module of the operation). Given two positive numbers, a and n, a modulo n (a%n, abbreviated as a mod n) is the rest of the Euclidian division of a by n, where a is dividend and n is divider. This operation can satisfy also the following formula a*(a//b)+(a%b) 26%5 Almost 26=5*5+1 26%5=1
23rd Sep 2022, 1:43 PM
ALI Moussa Kadjalla
ALI Moussa Kadjalla - avatar
0
The modulo returns the remainder of a division 25 %5 gives us 5 remainder 0 That 0 is the result of a modulo
23rd Sep 2022, 4:32 PM
Jonathan Amobi
Jonathan Amobi - avatar
0
Solo ok
23rd Sep 2022, 5:51 PM
ALI Moussa Kadjalla
ALI Moussa Kadjalla - avatar
0
Because modulo operator is used get the remainder.
24th Sep 2022, 4:53 PM
EVIL HUNTER
0
So modulo means the remainder after a division like when you dive 10%5 then remainder is 0 because 5 is divide 10 and nothing else is remain.
24th Sep 2022, 7:10 PM
Vijay Banjara
Vijay Banjara - avatar
- 1
Mifuko gives the remainder value in an operation and is denoted by % which is commonly known as the percentage sign. Example: print(2 % 5) = 1 Here 1 is the remainder after the calculation. Meaning that here we don't divide everything. If there be a remainder then must be noted.
24th Sep 2022, 11:30 PM
Walie Ojwallah
Walie Ojwallah - avatar