Como representar um número complexo z = x + yi?
1 Resposta
Seria fazendo a inclusão de 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));
}
Veja funcionando no ideone. E no repl.it. Também coloquei no GitHub para referência futura.