It seems like two very simple operators, but it is not easy to master and use them well. This article is a summary of all aspects of such operators, and I hope it will be helpful to you.
Division operator "/". Binary operators with left-bound attributes. When all the values involved in the calculation are integer, the result is integer and the decimal point is removed. If one of the computations is real, the result is double-precision real.
For example:
5/2 = 2, 1/2 = 0
5/2. 0 = 2.5
The remainder operator "%", a binary operator, with a left combination. The amount involved in the calculation isInteger. The result of the remainder operation is equalRemainder.
For example:
5% 2 = 1,1% 2 = 1
The result of 5% 2.0 and 5.0% 2 is a syntax error.
Turn: when the number of current faces is smaller than the following
In fact, the remainder operation can be viewed
A % B = a-(int) (a/B) * B
1% 2 = 1
2% 5 = 2
A % B
If a <B, the quotient is 0, and the remainder is.
Ha, this relational expression a % B = a-(int) (a/B) * B is explained in this way.
First calculate (a/B), then a-(a/B value), and then multiply by B
Example 1.
100 divided by 2 = 50
If the result is an integer, the value is 0 (the reason is that the value of 100 divided by 2 is an integer, not 50 ............. )
Example 2.
9 divided by 2 = 4.5
Then, multiply 4 by 2 = 8.
The result of 9-8 is the remainder.
In C, what are the values of-3/16, 16/-3,-3%, and 16%-3?
The difference between the positive and negative signs is the same as the General Arithmetic. The symbols are the same as positive signs, and the differences are negative.
The positive and negative trade of the remainder symbol is the same as that of the divisor.
-3/16 = 0 16/-3 =-5-3% 16 =-3 16%-3 = 1
FM: http://blog.163.com/lvjin658101@yeah/blog/static/162888047201121582012546/