tan()

The tan() function returns the tangent of an angle given in radians.

Syntax

tan(x)

The x parameter represents an angle measured in radians. One radian is equal to 180/π degrees (where π (Pi) = 3.14159…). If x is equal to π ± n/π (where n is a natural number), then a domain error will occur.

Example

The following example returns the tangent of 0 with the tan() function:

#include <iostream>
#include <cmath>
int main() {
double x = 0;
double result;
result = std::tan(x);
std::cout << "The tangent of " << x << " is " << result << ".\n";
}

This produces the following output:

The tangent of 0 is 0.

Codebyte Example

The following example is runnable and uses the tan() function to find the tangent of &pi;/4:

Code
Output
Loading...

Contributors

Interested in helping build Docs? Read the Contribution Guide or share your thoughts in this feedback form.

Learn C++ on Codecademy