In this C++ tutorial, you will learn how to find the tangent of an angle using tan() function of cmath, with syntax and examples.

C++ tan()

C++ tan() returns tangent of angle given in radians.


The syntax of C++ tan() is



xAngle in radians.


The return value depends on the type of value passed for parameter x. The return value of tan(x) is

  • double if x is double.
  • float if x is float.
  • long double if x is long double.

The synopsis of tan() function is

double tan(double x);
float tan(float x);
long double tan(long double x);
double tan(T x); // for integral type argument values

tan() is a function of cmath library. Include cmath library in the program, if using tan().



In this example, we read an angle value into x, from the user, and find the tangent of this angle using tan() function.

C++ Program

#include <iostream>
using namespace std;

int main() {
    float x;
    cout << "Enter an angle (in radians) : ";
    cin >> x;
    double result = tan(x);
    cout << "tan(" << x << ") : " << result << endl;


Enter an angle (in radians) : 1.5
tan(1.5) : 14.1014
Program ended with exit code: 0
Enter an angle (in radians) : 0
tan(0) : 0
Program ended with exit code: 0


In this C++ Tutorial, we learned the syntax of C++ tan(), and how to use this function to find the tangent of an angle, with the help of examples.