What is the operation rule for finding the remainder in…

In the C language, the rule for finding the remainder is to use division to obtain both the quotient and remainder. When two integers a and b are divided, the quotient is the result of integer division, and the remainder is the modulus when the dividend is divided by the divisor. The specific rule is as follows:

  1. If a and b are both positive integers, the quotient of a divided by b is the integer part, and the remainder is the remainder obtained when a is divided by b.
  2. If both a and b are negative integers, the quotient of a divided by b is the integer part, and the remainder is the remainder obtained when a is divided by b.
  3. If a is a positive integer and b is a negative integer, then the quotient of a divided by b is the next integer after the integer part, and the remainder is the remainder obtained when a is divided by b.
  4. If a is a negative integer and b is a positive integer, the quotient of a/b is the integer part of the previous integer and the remainder is the remainder obtained from the division of a by b. It is important to note that the modulus operator in the C language is %. For example, the value of the expression 5 % 2 is 1, and the value of the expression -5 % 2 is -1.
bannerAds