Facebook Page Twitter Page LinkedIn Page
× C++ Standard Library C++ STL Library


The C++ cmath tan() function is used to return trigonometric tangent of an angle (angle should be in radians).

Syntax

double tan (double x);
float tan (float x);
long double tan (long double x);
double tan (double x);
float tan (float x);
long double tan (long double x);
// additional overloads for integral types
double tan (T x);           

Parameters

x Specify the angle in radian.

Return Value

Returns the trigonometric tangent of an angle.

Example:

In the below example, tan() function is used to find out the trigonometric tangent of an angle.

#include <iostream>
#include <cmath>

using namespace std;
 
int main (){
  //M_PI - value of PI from math.h
  cout<<tan(M_PI/6)<<"\n";
  cout<<tan(M_PI/4)<<"\n";
  cout<<tan(M_PI/3)<<"\n";
  return 0;
}

The output of the above code will be:

0.57735
1
1.73205

❮ C++ <cmath> Library