How to implement remainder in C language

藏色散人
Release: 2020-05-11 13:34:32
Original
8428 people have browsed it

How to implement remainder in C language

Implementation method of remainder in C language

The remainder operator is "%", which is a binary operator in C language and requires two operands All are integers. The remainder is found to have the same sign as the dividend.

Recommended: "c Language Tutorial"

X%Y

1. It is very simple when X and Y are both positive numbers, such as: 12 %5==2;

2. When there are negative numbers,

(1) When they have different signs:

          if |x|>|y|
             ans:x+y
          else
            ans: x
eg:  -6%5==-1,6%(-5)==1,5%-6==5,-5%6==-5
Copy after login

(2) When they have the same sign, the two numbers will be Treated as a positive integer, but with a negative sign added to the result.

eg: -1%-5==-1,-6%-5==-1,-4%-5==-4,-5%-6==-5.
Copy after login

The above is the detailed content of How to implement remainder in C language. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact [email protected]
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!