Open In App

conj() function in C++ with Examples

Improve
Improve
Like Article
Like
Save
Share
Report

The conj() function is defined in the complex header file. This function is used to find the conjugate of the complex number z. If we represent a complex number z as (real, img), then its conjugate is (real, -img).
Syntax: 
 

template<class T> complex<T> 
     conj (const complex<T>& Z);

Parameter: 
 

  • z: This method takes a mandatory parameter z which represents the complex number.

Return value: This function returns the conjugate of the complex number z.

Time Complexity: O(1)

Auxiliary Space: O(1)
Below programs illustrate the conj() function for complex number in C++:
Example 1:-
 

CPP




// C++ program to demonstrate
// example of conj() function.
  
#include <bits/stdc++.h>
using namespace std;
  
// driver program
int main ()
{
  complex<double> complexnumber (3.0, 2.4);
  
  cout << "The conjugate of " << complexnumber << " is: ";
  
  // use of conj() function
  cout << conj(complexnumber) << endl;
  return 0;
}


Output: 

The conjugate of (3,2.4) is: (3,-2.4)

 

Example 2:-

CPP




// C++ program to demonstrate
// example of conj() function.
  
#include <bits/stdc++.h>
using namespace std;
  
// driver program
int main ()
{
  complex<double> complexnumber (2.0, 9.0);
  
  cout << "The conjugate of " << complexnumber << " is: ";
  
  // use of conj() function
  cout << conj(complexnumber) << endl;
  return 0;
}


Output: 

The conjugate of (2,9) is: (2,-9)

 



Last Updated : 14 Mar, 2023
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads