Home >Backend Development >C#.Net Tutorial >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
(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.
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!