pow() function for complex number in C++

The pow() function for complex number is defined in the complex header file. This function is the complex version of the pow() function. This function is used to calculate the complex power of base x raised to the y-th power.

Syntax:

template<class T> complex<T> pow (const complex<T>& x, int y);



or,
template<class T> complex<T> pow (const complex<T>& x, const complex<T>& y);

or,
template<class T> complex<T> pow (const complex<T>& x, const T& y);

or,
template<class T> complex<T> pow (const T& x, const complex<T>& y);

Parameter: This method accepts two parameters:

  • x: It represents the base as a complex value.
  • y: It represents the exponent as a complex value.

Return value: This function returns the complex power of base x raised to the y-th power.

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

Example 1:-

filter_none

edit
close

play_arrow

link
brightness_4
code

// c++ program to demonstrate
// example of pow() function.
  
#include <bits/stdc++.h>
using namespace std;
  
// driver program
int main()
{
    // initializing the complex: (1.0+2.0i)
    complex<double> complexnumber(1.0, 2.0);
  
    // use of pow() function for complex number
    cout << "(1.0, 2.0)^2 = "
         << pow(complexnumber, 2)
         << endl;
  
    return 0;
}

chevron_right


Output:

(1.0, 2.0)^2 = (-3,4)

Example 2:-

filter_none

edit
close

play_arrow

link
brightness_4
code

// c++ program to demonstrate
// example of pow() function.
  
#include <bits/stdc++.h>
using namespace std;
  
// driver program
int main()
{
    // initializing the complex: (2.0+1.0i)
    complex<double> complexnumber(2.0, 1.0);
  
    // use of pow() function for complex number
    cout << "(2.0, 1.0)^3 = "
         << pow(complexnumber, 3)
         << endl;
  
    return 0;
}

chevron_right


Output:

(2.0, 1.0)^3 = (2,11)


My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.