# include # include // // You must include complex.h in order to get the complex data type // and the associated complex mathematical functions. // # include int main ( ) { // // A complex number has "complex" data type. // A complex value can be defined by "x+y*I". // complex a = { 1.0 + 2.0 * I}; complex b = 3.0 * I; complex c; float d = 7.0; double e = 1.5E2; int f = 77; // // Print the initial values. // A complex number is treated as a pair of real values. // printf ( "\n" ); printf ( " Complex a = (%g,%g)\n", a ); printf ( " Complex b = (%g,%g)\n", b ); printf ( " Complex c = (%g,%g)\n", c ); printf ( " Float d = %g\n", d ); printf ( " Double e = %g\n", e ); printf ( " Int f = %i\n", f ); // // Do a few calculations and print. // CABS is the absolute value of a complex number. // CIMAG is the imaginary part (and CREAL is the real part) // CSIN is the sine, and so on. // c = a * b; d = cabs ( a ); e = cimag ( b ); b = csin ( a ); printf ( " Complex c = a*b = (%g,%g)\n", c ); printf ( " Float d = cabs(a) = %g\n", d ); printf ( " Double e = cimag(b) = %g\n", e ); printf ( " Complex b = csin(a) = (%g,%g)\n", b ); return; }