tan()

Published Nov 30, 2022
Contribute to Docs

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:

us
Visit us
code
Hide code
Code
Output
Hide output
Hide output
Loading...

All contributors

Looking to contribute?

Learn C++ on Codecademy