×

C++ Tutorial

C++ Data types

C++ Operators & Keywords

C++ Conditional Statements

C++ Functions

C++ 'this' Pointer, References

C++ Class & Objects

C++ Constructors & Destructors

C++ Operator overloading

C++ 11 (Advance C++)

C++ Preparation

C++ Header Files & Functionsr

Data Structure with C++

C++ - Miscellaneous

C++ Programs

Trigonometric functions in C++

C++ Trigonometric functions: Here, we are going to learn about the various trigonometric functions like cos(), sin(), tan(), acos(), asin(), atan() and atan2() with example.
Submitted by IncludeHelp, on April 28, 2019

C++ Trigonometric functions

Trigonometric functions are also called circular functions or angle functions or goniometric functions, which are used to trigonometric computations like computing cosine, sine, tangent values.

List of trigonometric functions

Here is the list of all trigonometric functions with descriptions and their syntaxes,

Trigonometric functions Description Syntax
cos() It returns the cosine of an angle of x radians. cos(x)
sin() It returns the sine of an angle of x radians. sin(x)
tan() It returns the tangent of an angle of x radians. tan(x)
acos() It returns the arc cosine of x in radians. acos(x)
asin() It returns the arc sine of x in radians. asin(x)
atan() It returns the arc tangent of x in radians. atan(x)
atan2() It returns the arc tangent of y/x in radians. atan2(y,x)
cosh() Ut returns the hyperbolic cosine of the given value. cosh(x)
sinh() It returns the hyperbolic sine of the given value. sinh(x)
tanh() It returns the hyperbolic tangent of the given value tanh(x)
acosh() It returns nonnegative area hyperbolic cosine of the given value acosh(x)
asinh() It returns the area hyperbolic sine of the given value asinh(x)
atanh() Ut returns find the area hyperbolic tangent of the given value atanh(x)

Example of C++ Trigonometric Functions

// C++ code to demonstrate the example of 
// trigonometric functions

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

// main() section
int main()
{
    float x;
    float y;
    
    x = 0.25;
    cout<<"cos("<<x<<") : "<<cos (x)<<endl;
    cout<<"sin("<<x<<") : "<<sin (x)<<endl;
    cout<<"tan("<<x<<") : "<<tan (x)<<endl;
    cout<<"acos("<<x<<"): "<<acos(x)<<endl;
    cout<<"asin("<<x<<"): "<<asin(x)<<endl;
    cout<<"atan("<<x<<"): "<<atan(x)<<endl;
    y = 1.0;
    cout<<"atan2("<<y<<","<<x<<"): "<<atan2(y,x)<<endl;    
    
    return 0;
}

Output

cos(0.25) : 0.968912
sin(0.25) : 0.247404
tan(0.25) : 0.255342
acos(0.25): 1.31812
asin(0.25): 0.25268
atan(0.25): 0.244979
atan2(1,0.25): 1.32582

Reference: C++ cmath header



Comments and Discussions!

Load comments ↻





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