What is cpow() in C?

cpow() is a built-in function defined in the <complex.h> header in C.

The function prototype is:

double complex cpow(double complex expression, double complex power)

Functionality

cpow() is used to compute complex power functions.

The first input parameter, expression, defines the complex expression to be raised to a power.

The second input parameter defines the power to which the expression will be raised.

The function returns the computed complex result.

The cpow() function

Code

#include <stdio.h>
#include <complex.h>
int main(void)
{
double complex z = cpow(2+4.0*I, 2);
printf("(2+4i)^2 = %.1f%+.1fi\n", creal(z), cimag(z));
//here we pass both inputs as complex
double complex z2 = cpow(2+4.0*I, I);
printf("(2+4i)^i = %f%+fi\n", creal(z2), cimag(z2));
return 0;
}

Free Resources

Copyright ©2025 Educative, Inc. All rights reserved