Program to evaluate powers of complex numbers I'm trying to develop a simple program to evaluate integral powers of a complex number \$z\$ , that is, \$z^n\$, where \$z\$ is in the algebrical form \$a+i b\$ and \$n \in \mathbb{Z} ^{*} _{+}\$. 

How I was trying to proceed:

First, I defined a product function, and next I intended to define a exponentiation function inside of which I iterated the product function (the code can bee seen below). Is it correct? Is there a more efficient alternative for doing that?

    include &lt;stdio.h&gt;
    include &lt;math.h&gt;

    struct complex {
        float real,imag;
    };

    struct complex product (struct complex x, struct complex y){
    /* using the distributive property, (a+ib)(c+id) = (ac-bd)+i(ad+bc)*/
        struct complex z;
        z.real = (x.real * y.real)- (x.imag * y.imag);
        z.imag = (x.real * y.imag) + (x.imag * y.real);
    return z;
    }      

    struct complex exponentiation (struct complex z, int n){
        int i;
        struct complex w;
        w = z;
        for (i=1, i&lt;n, i++)
            w = product (w,z);
    return w;
    }
C has a built-in complex type and a cpow() function since C99.  You seem to be reinventing-the-wheel.

Only in rare circumstances should you use float.  In most cases, you should use double instead.

Exponentiation of complex numbers is better done using the polar representation:

$$z = r e^{i\theta}$$

where

$$\begin{align}
z &amp;= a + i b \\
r &amp;= \sqrt{a^2 + b^2} \\
\theta &amp;= \arctan{\frac{b}{a}}
\end{align}$$

then

$$z^n = (r e^{i\theta})^n = r\,^n e^{i\ n \theta}$$

For non-trivial values of \$n\$, you would be better off converting to a polar representation, performing the exponentiation, and converting back to the Cartesian representation.