Explanation for % and / | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
- 1

Explanation for % and /

never really understood what % and / mean, can someone explain and give examples? thanks!

7th Dec 2016, 6:39 AM
Yahel Rosen
Yahel Rosen - avatar
2 Answers
+ 5
/ is the sign for division % is the sign for mod which is the remainder of a disivion when u use integer variables the outcome of the division will also be an integer - so if for example i have int x=14,y=3; if u would now go to your calculator and check the value of 14/3 it will show 4.666666 but in your program (since x and y are integers) x/y will produce 4 if u will do x%y the outcome is the reminder of the division what does it mean? the division produced 4 but 4*y (4*3) is only 12 so the reminder is 14-12 = 2 just a few more examples 4/2 = 2 4%2 = 0 5/2 = 2 5%2 = 1 10/3 = 3 10%3 = 1 10/6 = 1 10%6 = 4
7th Dec 2016, 6:59 AM
Ethan
Ethan - avatar
+ 1
thanks for the answer, now its clear 😀
7th Dec 2016, 7:00 AM
Yahel Rosen
Yahel Rosen - avatar