C++ STL 中的 sinh() 函式
sinh() 函式返回給定角度(以弧度為單位)的雙曲正弦值。它是 C++ STL 中的內建函式。
sinh() 函式的語法如下所示。
sinh(var)
從語法中可以看出,函式 sinh() 接受一個數據型別為 float、double 或 long double 的引數 var。它返回 var 的雙曲正弦值。
一個在 C++ 中展示 sinh() 用法的程式如下所示。
例項
#include <iostream> #include <cmath> using namespace std; int main() { double d = 5, ans; ans = sinh(d); cout << "sinh("<< d <<") = " << ans << endl; return 0; }
輸出
sinh(5) = 74.2032
在上述程式中,首先初始化變數 d。然後使用 sinh() 找出 d 的雙曲正弦值並存儲在 ans 中。最後,顯示 ans 的值。以下程式碼片段展示了此過程。
double d = 5, ans; ans = sinh(d); cout << "sinh("<< d <<") = " << ans << endl;
如果以度為單位提供值,則在使用 sinh() 函式之前,需要將其轉換為弧度,原因是它返回給定角度(以弧度為單位)的雙曲正弦值。展示此過程的程式如下。
例項
#include <iostream> #include <cmath> using namespace std; int main() { double degree = 60, ans; degree = degree * 3.14159/180; ans = sinh(degree); cout << "sinh("<<degree<<") = "<< ans << endl; return 0; }
輸出
sinh(1.0472) = 1.24937
在上述程式中,值以度為單位給出。因此將其轉換成弧度,然後使用 sinh() 獲得雙曲正弦。最後,顯示輸出。如下面程式碼片段所示。
double degree = 60, ans; degree = degree * 3.14159/180; ans = sinh(degree); cout << "sinh("<<degree<<") = " << ans << endl;
廣告