Possible Duplicate:
How to work with complex numbers in C?
So I have this piece of C code that compiles with errors saying that ‘complex’ does not name a type:
#include <stdio.h>
#include <complex.h>
#include <math.h>
int main ()
{
int B=9;
double theta;
double complex w;
float x,y;
x= 5*cos (theta) - 2;
y= 5*sin (theta);
double complex z=x+y*I;
w=z+(B/z);
for(theta=0;theta<=360;theta=+30)
{ printf ("%.2f %.2f %.2f %.2f",creal(z), cimag(z),y,creal(w), cimag(w));
printf ("/n");
}
return 0;
system ("pause");
}
I already include the <complex.h> so why is there still an error for the ‘complex’. There are also other errors, but let just focus on this one first.
Are you using GCC as your compiler? If yes, you need to enable C99 support by using the
-std=c99or-std=gnu99compiler flag.Also, declare variables before you use them. Here:
neither
xnoryhave been declared yet. Of course you also need to initialize them. For example: