-6

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.

3 Answers3

1

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 :

  1. When the dividend is greater than the divisor, it will give the remainder.

10 % 3 = 1

  1. When the dividend is smaller than the divisor, then the dividend itself is the remainder.

3 % 10 = 3

vegan_meat
  • 878
  • 4
  • 10
0
1 % 10 =    10 ) 1 ( 0
                -0
               ------
     Remainder = 1
0

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.