How to represent complex numbers in C?

2

How to represent a complex number z = x + yi?

    
asked by anonymous 04.10.2016 / 02:35

1 answer

6

Would include complex.h :

#include <stdio.h>
#include <complex.h>

int main() {
    double x = 1.0;
    double y = 2.0;
    double complex z = x + y * I;
    printf("%.2f %+.2fi\n", creal(z), cimag(z));
}

See working on ideone and CodingGround .

    
04.10.2016 / 02:44