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 <stdio.h>
include <math.h>
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<n, i++)
w = product (w,z);
return w;
}