无涯教程-sin(x)函数

98 阅读1分钟

该函数用于查找以弧度表示的角度的正弦值。

sin - 语法

float sin(float x);
float sin(double x);
float sin(long double x);
double sin(integral x);

Note: 如果传递的值是整数类型,则将其强制转换为double。

sin - 参数

x :以弧度表示的值。

sin - 返回值

它返回弧度在[-1,1]范围内的给定角度的正弦值。

sin - 例子1

让我们看一个简单的例子,当x的值为正时。

#include 
#include
using namespace std;
int main()
{  
  double degree=60;  
  double radian=degree*3.14/180;  
  cout<<"Sine of an angle is : "<<sin(radian);  
  return 0;  
}  

输出:

Sine of an angle is : 0.86576   

在此示例中,当度数等于60时,sin()函数计算角度的正弦值。

sin - 例子2

让我们看一个简单的例子,当x的值为负数时。

#include 
#include
using namespace std;
int main()
{  
  double degree= -50;  
  double radian=degree*3.14/180;  
  cout<<"Sine of an angle is : "<<sin(radian);  
  return 0;  
}  

输出:

Sine of an angle is : -0.76576 

在他的示例中,sin()函数在度的值为负(即-50)时找到角度的正弦值。

参考链接

www.learnfk.com/c++/cpp-mat…