English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

C++ tan() 函数使用方法及示例

C++ Fonction de bibliothèque <cmath>

C ++中的tan()函数返回以弧度为单位的角度(参数)的正切值。

此函数在<cmath>头文件中定义。

[数学] tan x = tan(x)

tan()原型(从C ++ 11标准开始)

double tan(double x);
float tan(float x);
long double tan(long double x);
double tan(T x); //为整型

tan()参数

tan()函数采用一个以弧度为单位的强制性参数(可以为正,负或0)。

tan()返回值

tan()函数返回[-∞,∞]范围内的值。

Exemple1:tan()如何在C ++中工作?

#include <iostream>
#include <cmath>
using namespace std;
int main()
{ 
  long double x = 0.99999, result;
  result = tan(x);
  cout << "tan(x) = " << result << endl;
  
  double xDegrees = 60.0;
  //利用tan()函数将度数转换为弧度
  result = tan(xDegrees*3.14159/180);
  cout << "tan(x) = " << result << endl;
  return 0;
}

Lorsque le programme est exécuté, la sortie est :

tan(x) = 1.55737
tan(x) = 1.73205

Exemple2:Fonction tan() avec type de données entière

#include <iostream>
#include <cmath>
using namespace std;
int main()
{
  long int x = 6;
  double result;
  result = tan(x);
  cout << "tan(x) = " << result;
  
  return 0;
}

Lorsque le programme est exécuté, la sortie est :

tan(x) = -0.291006

 C++ Fonction de bibliothèque <cmath>