English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
C ++tan() Function Usage and Example
This function returns the tangent value of the angle (parameter) in radians as returned by the tan() function in<cmath>defined in the header file.
[Math] tan x = tan(x)
double tan(double x); float tan(float x); long double tan(long double x); double tan(T x); //is of integer type
The tan() function takes a mandatory parameter in radians (can be positive, negative, or 0).
The tan() function returns[-∞, ∞]values within the range.
#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; //Utilize the tan() function to convert degrees to radians result = tan(xDegrees*3.14159/180); cout << "tan(x) = " << result << endl; return 0; }
When running the program, the output is:
tan(x) = 1.55737 tan(x) = 1.73205
#include <iostream> #include <cmath> using namespace std; int main() { long int x = 6; double result; result = tan(x); cout << "tan(x) = " << result; return 0; }
When running the program, the output is:
tan(x) = -0.291006