Open In App

tan() function for complex number in C++

The tan() function for complex numbers is defined in the complex header file. This function is the complex version of the tan() function. This function is used to calculate the complex tan of the complex number z. This function returns the tan of complex number z.

Syntax:  



tan(z);

Parameter: 

Return value: This function returns the tan() of complex number z.



Below programs illustrate the tan() function in C++:

Program 1:




// C++ program to demonstrate
// example of tan() function.
#include <iostream>
#include <complex>
using namespace std;
  
 
int main ()
{
  complex<double> complexnumber (0.0, 1.0);
  
  
  // use of tan() function for complex number
  cout << "The tan of " << complexnumber << " is "
                     << tan(complexnumber) <<endl;
  
  
  return 0;
}

Output: 
The tan of (0,1) is (0,0.761594)

 

Time Complexity: O(1)
Auxiliary Space: O(1)

PROGRAM 2:- 




// C++ program to demonstrate
// example of tan() function.
#include <iostream>
#include <complex>
using namespace std;
 
int main ()
{
  complex<double> complexnumber (1.0, 0.0);
  
  
  // use of tan() function for complex number
  cout << "The tan of " << complexnumber << " is "
                     << tan(complexnumber) << endl;
  
  
  return 0;
}

Output: 
The tan of (1,0) is (1.55741,0)

 

Time Complexity: O(1)
Auxiliary Space: O(1)


Article Tags :
C++