C++ tan()

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


[Mathematics] tan x = tan(x) [In C++ Programming]

tan() 原型(C++ 11 标准)

double tan(double x);
float tan(float x);
long double tan(long double x);
double tan (T x); // For integral type

tan() 参数

tan() 函数接受一个以弧度为单位的必需参数(可以是正数、负数或 0)。


tan() 返回值

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


示例 1:C++ 中的 tan() 如何工作?

#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;
  // converting degree to radians and using tan() fucntion
  result = tan(xDegrees*3.14159/180);
  cout << "tan(x) = " << result << endl;

  return 0;
}

运行程序后,输出将是

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

示例 2:带整数类型的 tan() 函数

#include <iostream>
#include <cmath>
using namespace std;

int main()
{
  long int x = 6;
  double result;

  result = tan(x);
  cout << "tan(x) = " << result;
  
  return 0;
}

运行程序后,输出将是

tan(x) = -0.291006

另请阅读

你觉得这篇文章有帮助吗?

我们的高级学习平台,凭借十多年的经验和数千条反馈创建。

以前所未有的方式学习和提高您的编程技能。

试用 Programiz PRO
  • 交互式课程
  • 证书
  • AI 帮助
  • 2000+ 挑战