該函數用於計算以弧度表示的角度的餘弦值。
用法
考慮弧度 'x'。語法是:
float cos(float x);
float cos(double x);
float cos(long double x);
double cos(integral x);
注意:如果傳遞的值是整數類型,則將其強製轉換為 double。
參數
x: 以弧度表示的值。
返回值
它返回 [-1,1] 範圍內的角度的餘弦值。
例子1
當 x 的值為正時,讓我們看一個簡單的例子。
#include <iostream>
#include<math.h>
using namespace std;
int main()
{
double degree=60;
double d=60*3.14/180;
cout<<"Cosine of an angle is:"<<cos(d);
return 0;
}
輸出:
Cosine of an angle is:0.50046
在本例中,cos() 函數計算角度等於 60 時的餘弦值。
例子2
當 x 的值為負時,讓我們看一個簡單的例子。
#include <iostream>
#include<math.h>
using namespace std;
int main()
{
double degree= -90;
double radian=degree*3.14/180;
cout<<"Cosine of an angle is:"<<cos(radian);
return 0;
}
輸出:
Cosine of an angle is:0.000796327
在本例中,cos() 函數在值為負時求角度的餘弦,但它與 cos(-x) =cos(x) 保持相同。
相關用法
- C++ Math cosh()用法及代碼示例
- C++ Math copysign()用法及代碼示例
- C++ Math ceil()用法及代碼示例
- C++ Math cbrt()用法及代碼示例
- C++ Math scalbn()用法及代碼示例
- C++ Math acosh()用法及代碼示例
- C++ Math asinh()用法及代碼示例
- C++ Math isgreater()用法及代碼示例
- C++ Math fabs()用法及代碼示例
- C++ Math islessgreater()用法及代碼示例
- C++ Math log2()用法及代碼示例
- C++ Math nearbyint()用法及代碼示例
- C++ Math tan()用法及代碼示例
- C++ Math log()用法及代碼示例
- C++ Math nextafter()用法及代碼示例
- C++ Math fdim()用法及代碼示例
- C++ Math isfinite()用法及代碼示例
- C++ Math erfc()用法及代碼示例
- C++ Math sinh()用法及代碼示例
- C++ Math scalbln()用法及代碼示例
注:本文由純淨天空篩選整理自 C++ Math cos()。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。