c语言 函数的参数传递示例
C ++ restder()函数 (C++ remainder() function)
remainder() functionis a library function ofcmathheader, it is used to calculate the remainder (IEC 60559), it accepts two parameters (numeratoranddenominator) and returns the remainder (floating-point) ofnumerator/denominatorrounded to nearest,
restder()函数是cmath标头的库函数,用于计算余数(IEC 60559),它接受两个参数(分子和分母),并返回四舍五入到最接近的分子/分母的余数(浮点数),
remainder = numerator - rquot * denominator
Where,rquotis the value ofnumerator/denominator(rounded to the nearest integral value with halfway cases rounded toward the even number.
其中,rquot是分子/分母的值(四舍五入为最接近的整数值,中位数为四舍五入为偶数)。
Syntax of remainder() function:
restder()函数的语法:
C++11:
C ++ 11:
double remainder (double numer, double denom);float remainder (float numer, float denom);long double remainder (long double numer, long double denom);double remainder (Type1 numer, Type2 denom);
Parameter(s):
参数:
numer, denom – represent the values ofnumeratoranddenominator.
numer,denom –表示分子和分母的值。
Return value:
返回值:
It returns the remainder.
它返回余数。
Note:
注意:
If the remainder is 0, then its sign is the same as the sign of numer.
如果余数为0,则其符号与numer的符号相同。
If the value of denom is 0, the result may either 0 or it may cause a domain error.
如果denom的值为0,则结果可能为0或可能导致域错误。
Example:
例:
Input:double x = 15.46;double y = 12.56;Function call:remainder(x, y);Output:2.9
C ++代码来演示restder()函数的示例 (C++ code to demonstrate the example of remainder() function)
// C++ code to demonstrate the example of// remainder() function#include <iostream>#include <cmath>using namespace std;// main() sectionint main(){double x;double y;x = 10;y = 2;cout << "remainder(" << x << "," << y << "): " << remainder(x, y);cout << endl;x = 5.3;y = 2;cout << "remainder(" << x << "," << y << "): " << remainder(x, y);cout << endl;x = 15.46;y = 12.56;cout << "remainder(" << x << "," << y << "): " << remainder(x, y);cout << endl;x = -10.2;y = 2;cout << "remainder(" << x << "," << y << "): " << remainder(x, y);cout << endl;return 0;}
Output
输出量
remainder(10,2): 0remainder(5.3,2): -0.7remainder(15.46,12.56): 2.9remainder(-10.2,2): -0.2
Reference: C++ remainder() function
参考: C ++ restder()函数
翻译自: /cpp-tutorial/remainder-function-with-example.aspx
c语言 函数的参数传递示例