Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Semrush - keyword research tool

Turn ChatGPT, Claude, Gemini, And CoPilot Into Your Personal Assistant, Business Coach, Content Creator, And More

AFFILIATE MARKETING Your all-in-one performance engine Manage affiliates, creators, and customer referrals in one unified platform—turning every partnership into measurable growth
Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

42,709 questions

55,473 answers

573 users

How to get the imaginary part of a complex number in C

3 Answers

0 votes
#include <stdio.h>
#include <complex.h>

int main(void)
{
    double complex z = 1.0 + 2.0 * I;
    
    double imaginary = cimag(z);
    
    printf("%lf", imaginary);
}





/*
run:

2.000000

*/

 



answered Jan 27, 2023 by avibootz
edited Jan 27, 2023 by avibootz
0 votes
#include <stdio.h>
#include <complex.h>

int main(void)
{
    double complex z = 1.0 - 2.0 * I;
    
    float imaginary = cimagf(z);
    
    printf("%f", imaginary);
}





/*
run:

-2.000000

*/

 



answered Jan 27, 2023 by avibootz
0 votes
#include <stdio.h>
#include <complex.h>

int main(void)
{
    double complex z = 2.0 + 3.0 * I;
    
    long double imaginary = cimagl(z);
    
    printf("%Lf", imaginary);
}





/*
run:

3.000000

*/

 



answered Jan 27, 2023 by avibootz

Related questions

1 answer 107 views
107 views asked Jan 24, 2023 by avibootz
1 answer 114 views
1 answer 105 views
105 views asked Jan 24, 2023 by avibootz
1 answer 95 views
95 views asked Jan 24, 2023 by avibootz
1 answer 104 views
104 views asked Jan 24, 2023 by avibootz
...