pow() function for complex number in C++


pow() or power function is a function used to calculate the power of a number. It is generally used in real numbers. Here, we will see its implementation of complex numbers.

Complex numbers are those numbers that can be represented as A + iB, where A is the real part and B is the complex part of the number.

The functions for the complex number in c++ are defined in the header file <complex.h>. Here, the pow() method for complex numbers is defined. It finds the complex power of a complex number to some power.

The method is applied to complex numbers takes two input parameters first a complex number base(C) and next to the exponent(a). It returns a complex number which C^a.

Input − C = 4 + 3i a = 2

Output − (7, 24)

Example

Program to find pow of complex number

 Live Demo

#include <iostream>
#include <complex>
using namespace std;
int main() {
   complex<double> complexnumber(4, 3);
   cout<<"Square of (4+ 3i) = "<<pow(complexnumber, 2)<<endl;
   return 0;
}

Output

Square of (4+ 3i) = (7,24)

Updated on: 17-Apr-2020

505 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements