C语言中如何将复数存进数组?

C99 里有复数:

#include <stdio.h>

#include <complex.h>

int main()

{

double complex z1 = 1.0 + 3.0 * I;

double complex z2 = 1.0 - 4.0 * I;

double complex f[20];

printf("Starting values: Z1 = %.2f + %.2fi\tZ2 = %.2f %+.2fi\n",

creal(z1), cimag(z1), creal(z2), cimag(z2));

..

}

===================

老的c 自己定义:

#include <stdio.h>

typedef struct {double r; double i; } complex;

main(){

complex c[2]={ {1.,3.},{1.,-4.0}}; // 初始化有2个复数元素的数组

complex r;

r.r = c[0].r + c[1].r;

r.i = c[0].i + c[1].i;

printf("real: %f img: %f\n",r.r,r.i);

}