Arithmetic/Complex: Difference between revisions

→‎{{header|C}}: print output and use same constants as other examples
(→‎{{header|C}}: Added a moderately tested user-defined version to make C99 people happy)
(→‎{{header|C}}: print output and use same constants as other examples)
Line 45:
#include <complex.h>
 
void cprint(double complex c)
{
printf("%lf%+lfI", creal(c), cimag(c));
}
void complex_operations() {
double complex a = 1.0 + 1.0I;
double complex b = 3.14159 + 1.25I2I;
 
double complex c;
 
printf("\na="); cprint(a);
printf("\nb="); cprint(b);
 
// addition
c = a + b;
printf("\na+b="); cprint(c);
// multiplication
c = a * b;
printf("\na*b="); cprint(c);
// inversion
c = 1.0 / a;
printf("\n1/c="); cprint(c);
// negation
c = -a;
printf("\n-a="); cprint(c); printf("\n");
}
</c>
 
{{workswith|C89}}
User-defined type:
<c>typedef struct{
Anonymous user