• Advertisement
Sign in to follow this  

complex output

This topic is 3707 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Advertisement
Never heard of cout being used to print out complex numbers in C.

Any way, why not this:
printf("%d+%di",real_part,imaginary_part);

Share this post


Link to post
Share on other sites
In C, you can get the real and imaginary part of a complex number via the creal() and cimag() functions for double complex numbers, crealf() and cimagf() for float complex numbers and creall() and cimagl() for long double complex numbers. They return double, float and long double values respectively, which can then be passed to printf() with the standard floating point format specifiers.

Share this post


Link to post
Share on other sites
I had tried that before but somethings wrong with the functions in complex.h. I can't use any of the functions in the header, but the _Complex structure still works.
I've also tried to specify the imaginary and real parts of the variable using x.real and x.imag.

Share this post


Link to post
Share on other sites
What's the problem? Do you get compiler errors? Runtime errors? Does you computer kick you in the shin while singing "The Devil Came Down to Georgia"?

Share this post


Link to post
Share on other sites
It says that their undefined. I'm includeing complex.h and I've looked into the file and the prototypes are in the header. I'm using dev-c++.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement