how I can use % | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

how I can use %

20th Aug 2016, 8:11 PM
sagir
sagir - avatar
6 Answers
+ 5
% (modulus) gives you the remainder of the euclidian division. For example: 60%7 = 4 (since 60 = 8*7 + 4) x%2 equals 0 if x is even, and 1 if it is odd x%10 gives you the last digit x%100 gives you the last two digits
21st Aug 2016, 5:20 AM
Zen
Zen - avatar
+ 1
For example if you have a number between 0 and 99 but just want zu have the last digit. So You do like "var last_digit = number%10 ;"
20th Aug 2016, 9:41 PM
jomaway
+ 1
% gives the remained of two numbers
30th Aug 2016, 2:21 AM
David Godswill
David Godswill - avatar
+ 1
% is a modulus operator. It will give you the remainder of two numbers. Example : 5%2 will give you 1 as remainder and 29%3 will give you 2 as remainder.
5th Sep 2016, 8:14 AM
Ritweek
Ritweek - avatar
0
just take a no. for example-32 followed by % sign followed by the no. by which you want to divide it let's take 6,it will show the reminder as result(res=2)
24th Sep 2016, 12:31 PM
shashank
0
It's useful if you want an algorithm that find a number that is multiple of another number. eg. document.write all the numbers multiple of 5. X = a%5; if (X = 0) than document.write (a); as you can see, if the result of modulus is 0 the number is multiple of 5.
25th Sep 2016, 7:10 PM
Tiago Fuelber
Tiago Fuelber - avatar