Home » C++ programming language

tan() function with example in C++

C++ tan() function: Here, we are going to learn about the tan() function with example of cmath header in C++ programming language?
Submitted by IncludeHelp, on April 27, 2019

C++ tan() function

tan() function is a library function of cmath header, it is used to find the tangent of the given number (angle), it accepts a number (x) and returns the tangent of angle x radians.

Syntax of tan() function:

    tan(x);

Parameter(s): x – is the value of an angle in radians whose tangent to be calculated.

Return value: double – it returns double type value that is the tangent of given angle x radians.

Example:

    Input:
    float x = 2.45;
    
    Function call:
    tan(x);    
    
    Output:
    -0.828017

C++ code to demonstrate the example of tan() function

// C++ code to demonstrate the example of 
// tan() function

#include <iostream>
#include <cmath>
using namespace std;

// main() section
int main()
{
    float x;
    
    x = -10.23;
    cout<<"tan("<<x<<"): "<<tan(x)<<endl;

    x = 0;
    cout<<"tan("<<x<<"): "<<tan(x)<<endl;    

    x = 2.45;
    cout<<"tan("<<x<<"): "<<tan(x)<<endl;    
    
    return 0;
}

Output

tan(-10.23): -1.04045
tan(0): 0
tan(2.45): -0.828017

Reference: C++ tan() function




Comments and Discussions!

Load comments ↻






Copyright © 2024 www.includehelp.com. All rights reserved.