#include <complex.h> #include <stdio.h> int main(int argc, char* argv[]) { float complex my_result; float _Complex my_complex1 = 3.0 + 4.0*I; float complex my_complex2 = 1.0 + 2.0*_Complex_I; my_result = my_complex1 + my_complex2; printf("Add: %f + %fi\n", creal(my_result), cimag(my_result)); my_result = my_complex1 * my_complex2; printf("Multiply: %f + %fi\n", creal(my_result), cimag(my_result)); return 0; }
Copyright © Scott Stevenson 2004-2015
by Eric Wing — Sep 17
#include <complex.h> #include <stdio.h> int main(int argc, char* argv[]) { float complex my_result; float _Complex my_complex1 = 3.0 + 4.0*I; float complex my_complex2 = 1.0 + 2.0*_Complex_I; my_result = my_complex1 + my_complex2; printf("Add: %f + %fi\n", creal(my_result), cimag(my_result)); my_result = my_complex1 * my_complex2; printf("Multiply: %f + %fi\n", creal(my_result), cimag(my_result)); return 0; }
Obj-C is a pure superset of C; no need to write your own class in this case.