c语言 函数的参数传递示例_C ++中带有示例的nearint()函数
c語言 函數的參數傳遞示例
C ++附近的int()函數 (C++ nearbyint() function)
nearbyint() function is a library function of cmath header, it is used to round the given value to an integral value based on the specified direction by fegetround() function. It accepts a value and returns the rounded integral value.
nearint()函數是cmath標頭的庫函數,用于通過fegetround()函數根據指定方向將給定值舍入為整數值。 它接受一個值并返回四舍五入的整數值。
Syntax of nearbyint() function:
附近的int()函數的語法:
C++11:
C ++ 11:
double nearbyint (double x);float nearbyint (float x); long double nearbyint (long double x);double nearbyint (T x);Parameter(s):
參數:
x – represents the value to round.
x –表示要取整的值。
Return value:
返回值:
It returns value rounded to nearby integral.
它返回四舍五入到附近整數的值。
Example:
例:
Input:double x = 123.4;Function call:nearbyint(x);Output:123Input:double x = 123.5;Function call:nearbyint(x);Output:124C ++代碼來演示Nearestint()函數的示例 (C++ code to demonstrate the example of nearbyint() function)
// C++ code to demonstrate the example of // nearbyint() function#include <iostream> #include <cmath> #include <fenv.h> // for fegetround() using namespace std;int main() {double x = 0.0;cout << "Specified rounding is: ";switch (fegetround()) {case FE_DOWNWARD:cout << "Downward" << endl;break;case FE_TONEAREST:cout << "To-nearest" << endl;break;case FE_TOWARDZERO:cout << "Toward-zero" << endl;break;case FE_UPWARD:cout << "Upward" << endl;break;default:cout << "Unknown" << endl;}x = 123.4;cout << "nearbyint(" << x << "): " << nearbyint(x) << endl;x = 123.5;cout << "nearbyint(" << x << "): " << nearbyint(x) << endl;x = 123.6;cout << "nearbyint(" << x << "): " << nearbyint(x) << endl;x = -123.4;cout << "nearbyint(" << x << "): " << nearbyint(x) << endl;x = -123.5;cout << "nearbyint(" << x << "): " << nearbyint(x) << endl;x = -123.6;cout << "nearbyint(" << x << "): " << nearbyint(x) << endl;return 0; }Output
輸出量
Specified rounding is: To-nearest nearbyint(123.4): 123 nearbyint(123.5): 124 nearbyint(123.6): 124 nearbyint(-123.4): -123 nearbyint(-123.5): -124 nearbyint(-123.6): -124Reference: C++ nearbyint() function
參考: C ++附近的int()函數
翻譯自: https://www.includehelp.com/cpp-tutorial/nearbyint-function-with-example.aspx
c語言 函數的參數傳遞示例
總結
以上是生活随笔為你收集整理的c语言 函数的参数传递示例_C ++中带有示例的nearint()函数的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: PHP登录表单提交前端验证,form表单
- 下一篇: lightgbm 保存模型 过大_机器学