I am new to programming . I knew that modulo operator gives remainder for example 7%2=1 but I didn't understand how 1%10= 1 . Can someone please explain it.
When the dividend
is smaller than the divisor
, then the dividend
itself is the remainder. means in your case 1%10
is 1
Points to remember regarding the '%' operator :
10 % 3 = 1
3 % 10 = 3
1 % 10 = 10 ) 1 ( 0
-0
------
Remainder = 1
Taking your example, when you say that 7%2 =1, it means the remainder is 1 and the quotient would be 3.
Similarly for 1%10,when we divide 1 by 10, the quotient is 0 but the remainder comes out to be 1.
Therefore 1%10=1.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.