c語言 函數的參數傳遞示例
C ++ restder()函數 (C++ remainder() function)
remainder() function is a library function of cmath header, it is used to calculate the remainder (IEC 60559), it accepts two parameters (numerator and denominator) and returns the remainder (floating-point) of numerator/denominator rounded to nearest,
restder()函數是cmath標頭的庫函數,用于計算余數(IEC 60559),它接受兩個參數( 分子和分母 ),并返回四舍五入到最接近的分子 / 分母的余數(浮點數),
remainder = numerator - rquot * denominator
Where, rquot is the value of numerator/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 of numerator and denominator.
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() section
int 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): 0
remainder(5.3,2): -0.7
remainder(15.46,12.56): 2.9
remainder(-10.2,2): -0.2
Reference: C++ remainder() function
參考: C ++ restder()函數
翻譯自: https://www.includehelp.com/cpp-tutorial/remainder-function-with-example.aspx
c語言 函數的參數傳遞示例