Skip to content
Related Articles

Related Articles

Improve Article

pow() function for complex number in C++

  • Last Updated : 11 Oct, 2018

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:-




// 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;
}
Output:
(1.0, 2.0)^2 = (-3,4)

Example 2:-




// 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;
}
Output:
(2.0, 1.0)^3 = (2,11)
Want to learn from the best curated videos and practice problems, check out the C++ Foundation Course for Basic to Advanced C++ and C++ STL Course for foundation plus STL.  To complete your preparation from learning a language to DS Algo and many more,  please refer Complete Interview Preparation Course.



My Personal Notes arrow_drop_up
Recommended Articles
Page :