Excuse me, i still dont understand about / and %, can you example for me? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Excuse me, i still dont understand about / and %, can you example for me?

6th Apr 2017, 4:39 AM
Bodhi
Bodhi - avatar
14 Answers
+ 12
Gosh, the examples here. / is for division. % is for modulus. 5/3 == 1 with remainder 2 5%3 is 2 (It returns the remainder of 5/3) Likewise, 4/3 == 1 with remainder 1 4%3 is 1 (Because remainder of 4/3 is 1) As simple as that.
6th Apr 2017, 5:38 AM
Hatsy Rei
Hatsy Rei - avatar
+ 11
Hi Dia :) "/" is for division "%" is for modulus ------------------------------------------------------------- Example of DIVISION: 6/3 = 2 This would return 2 due to the fact that 3 goes into 6 twice. In other words, it gives you the quotient. ------------------------------------------------------------- Example #1 of MODULUS: 10%3 = 1 Modulus gives the remainder of the division of one number by another. It's like you were doing a regular division (10/3) but you don't care about the quotient of that division (3), instead, you want the remainder (1) So, in this example the modulus would return 1 due to the fact that 3 goes into 10 three times and then gives the 1 that is left over. ------------------------------------------------------------ Example #2 of MODULUS: What if you reverse the previous statement? 3%10 = 3 Here's how to solve it: - Step 1: Find the quotient 3/10 = 0.3 - Step 2: Take the left side of the decimal. So we take 0 from 0.3 (this is what the "floor" function does) - Step 3: Multiply that 0 by 10 (the denominator) 0*10 = 0 - Step 4: Subtract 0 (the result) from 3 (the numerator) 3 - 0 = 3 That's it 😊 ------------------------------------------------------------ You might find this formula useful for MODULUS: a%b = a - floor(a/b)*b Application of the formula: 3%10 = 3 - floor(3/10)*10 3%10 = 3 - floor(0.3)*10 3%10 = 3 - 0*10 3%10 = 3 - 0 3%10 = 3 Hope this helps you 😊
6th Apr 2017, 7:06 AM
Pao
Pao - avatar
+ 8
@Dia, it means that how many times 1 comes in the table of 3, ans is 0. 1/3=0 and 1%3=1 how many times 2 comes in table of 3, 0 time 2/3=0 and 2%3=2 how many times 3 comes in table of 3, 1 time 3/3=1 and 3%3=0 how many times 4 comes in table of 3, 1 time 4/3=1 and 4%3=1 how many times 5 comes in table of 3, 1 time with remainder of 2, 5/3=1 and 5%3=2
6th Apr 2017, 5:33 AM
Sachin Artani
Sachin Artani - avatar
+ 7
/ is division operator, outputs the quotient of calculation, eg. 5/2=2 while % is modulo operator, outputs the remainder of calculation, eg. 5%2=1
6th Apr 2017, 5:13 AM
Sachin Artani
Sachin Artani - avatar
+ 4
"/ "is simple division so d output is the quotient ie 6/2 =3//its just lik division "%" tells the remainder after division ie 7%2=1 **hope this helps
6th Apr 2017, 7:19 AM
Saumya
Saumya - avatar
+ 2
i really dont understand about 0*3+1 where 0 come from?
6th Apr 2017, 5:32 AM
Bodhi
Bodhi - avatar
+ 2
ooo now i understood now thank for the explanation
6th Apr 2017, 5:38 AM
Bodhi
Bodhi - avatar
+ 1
/ is division. % gives you the rest. 1%3=1 because 1=0*3+1 2%3 = 2 because 2=0*3+2 3%3=0 because 3=1*3+0 4%3 = 1 because 4=1*3+1
6th Apr 2017, 4:46 AM
1of3
1of3 - avatar
+ 1
thank you, but i still don't understand about "1%3=1 because 1=0*3+2" where 0 come from?
6th Apr 2017, 4:51 AM
Bodhi
Bodhi - avatar
+ 1
How often does 3 fit into 1? Zero times. What do you have to add still? One. It's division with remainder. Fourth grade. Before you learn about fractions.
6th Apr 2017, 5:16 AM
1of3
1of3 - avatar
+ 1
it's very hard to understand about % and/ please example more detail about it.
6th Apr 2017, 5:21 AM
Bodhi
Bodhi - avatar
+ 1
thanks about information
6th Apr 2017, 5:41 AM
Bodhi
Bodhi - avatar
+ 1
thank you all for the material
6th Apr 2017, 3:45 PM
Bodhi
Bodhi - avatar
+ 1
may i ask why 3/10=0.3 why not 3
6th Apr 2017, 3:47 PM
Bodhi
Bodhi - avatar