In this post today I am going to explain the C++ Math tan() Function.
The tangent of an angle provided in radians is found using this function.
Syntax of tan() function:
Consider a radian ‘x’. The syntax would be:
float tan(float x);
double tan(double x);
long double tan(long double x);
double tan(integral x);
Note that if the value is an integral type, it will be converted to double.
Parameter:
x: The value given in radian.
Return Value:
It returns the tangent of an angle given in radian.
Example-1:
Let’s have a look at a basic case where x is positive.
#include <iostream> #include<math.h> using namespace std; int main() { float degree=10; float radian=degree*3.14/180; cout<<"Tangent of an angle is : "<<tan(radian); return 0; }
Output:
Tangent of an angle is : 0.176236
When the value of a degree is equal to10, the tan() function calculates the tangent of an angle.
Example-2:
Let’s look at a basic case where the degree value is negative.
#include <iostream> #include<math.h> using namespace std; int main() { float degree= -60; float radian=degree*3.14/180; cout<<"Tangent of an angle is :"<<tan(radian); return 0; }
output:
Tangent of an angle is :-1.72993
When the value of the degree is negative, such as-60, the tan() function calculates the tangent of an angle.