C++ STL 中的 cosh() 函式
cosh() 函式可返回以弧度為單位給定角度的雙曲餘弦。它是 C++ STL 中的內建函式。
cosh() 函式的語法如下。
cosh(var)
從語法中可以看出,函式 cosh() 接受一個 float、double 或 long double 資料型別引數 var。它返回 var 的雙曲餘弦。
以下是對 C++ 中 cosh() 的說明程式 −
示例
#include <iostream> #include <cmath> using namespace std; int main() { double d = 5, ans; ans = cosh(d); cout << "cosh("<< d <<") = " << ans << endl; return 0; }
輸出
cosh(5) = 74.2099
在上述程式中,首先對變數 d 進行初始化。然後使用 cosh() 查詢 d 的雙曲餘弦並存儲在 ans 中。最後顯示 ans 的值。以下程式碼片段演示了這一點。
double d = 5, ans; ans = cosh(d); cout << "cosh("<< d <<") = " << ans << endl;
如果以度數提供值,則在使用 cosh() 函式之前會將其轉換為弧度,因為它返回以弧度為單位給定角度的雙曲餘弦。以下是一個演示程式。
示例
#include <iostream> #include <cmath> using namespace std; int main() { double degree = 60, ans; degree = degree * 3.14159/180; ans = cosh(degree); cout << "cosh("<<degree<<") = " << ans << endl; return 0; }
輸出
cosh(1.0472) = 1.60029
在上述程式中,值是以度數給出的。因此,將其轉換為弧度,然後使用 cosh() 獲取雙曲餘弦。最後,顯示輸出。以下程式碼片段演示了這一點。
double degree = 60, ans; degree = degree * 3.14159/180; ans = cosh(degree); cout << "cosh("<<degree<<") = " << ans << endl;
廣告