C++教程
C++控制语句
C++函数
C++数组
C++指针
C++对象
C++继承
C++多态
C++抽象
C++常用
C++ STL教程
C++迭代器
C++程序

C++ Math cos()

C++ Math cos()

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

语法

考虑弧度" 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   
在此示例中,当度数等于60时,cos()函数将计算角度的余弦值。

示例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(-x)= cos(x)相同时,cos()函数将查找角度的余弦。

昵称: 邮箱:
Copyright © 2022 立地货 All Rights Reserved.
备案号:京ICP备14037608号-4