Related Articles

Related Articles

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

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)

Rated as one of the most sought after skills in the industry, own the basics of coding with our C++ STL Course and master the very concepts by intense problem-solving.




My Personal Notes arrow_drop_up
Recommended Articles
Page :