Suppose I did not know their size, which is not the case in this example, so I've allocated arrays dynamically, and this is my example:
Code:
#include <stdio.h>
#include <complex.h>
#include <stdlib.h>
int main (){
double *B,*A;
complex double *z;
int i,size=5;
A=malloc(size*sizeof(double));
B=malloc(size*sizeof(double));
z=malloc(size*sizeof(complex double));
for(i=0;i<size;i++){
A[i]=i*1.;
B[i]=i*2.;
z[i]=A[i]+B[i]*I;
}
for(i=0;i<size;i++)
printf("A= %f B=%fI Z=%f + %fI\n", A[i],B[i],creal(z[i]),cimag(z[i]));
free(z);
free(A);
free(B);
return 0;
}
and when I compilled:
Code:
[figura@localhost testes]$ gcc -c mat_complex.c
mat_complex.c:27:2: warning: no newline at end of file
[figura@localhost testes]$ gcc mat_complex.o
[figura@localhost testes]$ ./a.out
A= 0.000000 B=0.000000I Z=0.000000 + 0.000000I
A= 1.000000 B=2.000000I Z=1.000000 + 2.000000I
A= 2.000000 B=4.000000I Z=2.000000 + 4.000000I
A= 3.000000 B=6.000000I Z=3.000000 + 6.000000I
A= 4.000000 B=8.000000I Z=4.000000 + 8.000000I
[figura@localhost testes]$
Is this the right way to print?? If so, I think that now everything's right!! Now I can back to my big code. Thanks anduril462 and everybody!!