The division operator in C language is /, which can perform division on integers or floating-point numbers: Integer division: discard the decimal part and return an integer. Floating point division: retain the decimal part and return a floating point number. Note that dividing by 0 will result in an error, and integer division may overflow, requiring type conversion to obtain floating point results.
Division in C language
Division operation in C language is represented by /
operator , can perform division on integers or floating point numbers.
Integer division
Integer division discards the decimal part and returns an integer. For example:
<code class="c">int a = 10, b = 3; int result = a / b; // result 为 3</code>
Floating point division
Floating point division will retain the decimal part and return a floating point number. For example:
<code class="c">float a = 10.0, b = 3.0; float result = a / b; // result 为 3.333333</code>
Notes
<code class="c">int a = 10; float b = 3.0; float result = (float)a / b; // result 为 3.333333</code>
The above is the detailed content of How to write division in c language. For more information, please follow other related articles on the PHP Chinese website!