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:-
#include <bits/stdc++.h>
using namespace std;
int main()
{
complex< double > complexnumber(1.0, 2.0);
cout << "(1.0, 2.0)^2 = "
<< pow (complexnumber, 2)
<< endl;
return 0;
}
|
Output:
(1.0, 2.0)^2 = (-3,4)
Example 2:-
#include <bits/stdc++.h>
using namespace std;
int main()
{
complex< double > complexnumber(2.0, 1.0);
cout << "(2.0, 1.0)^3 = "
<< pow (complexnumber, 3)
<< endl;
return 0;
}
|
Output:
(2.0, 1.0)^3 = (2,11)
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...