简体   繁体   English

c 中的模运算符

[英]Modulo operator in c

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 .我知道模运算符给出余数,例如 7%2=1 但我不明白 1%10= 1 。 Can someone please explain it.有人可以解释一下吗。

When the dividend is smaller than the divisor , then the dividend itself is the remainder.dividend小于divisordividend本身就是余数。 means in your case 1%10 is 1意味着在你的情况下1%101

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

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.以您为例,当您说 7%2 =1 时,表示余数为 1,商为 3。

Similarly for 1%10,when we divide 1 by 10, the quotient is 0 but the remainder comes out to be 1.同样,对于 1%10,当我们将 1 除以 10 时,商为 0,但余数为 1。

Therefore 1%10=1.因此 1%10=1。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM