by Dinesh Thakur Category: Structure And Union

Let us use structure complex to represent a complex number and write a simple program containing only the main function. Thus, we can define structure complex either in the main function or before it as a global definition.

The addition of two complex numbers involves the addition of the real and imaginary parts of the two numbers. Let us use structure variables x and y to represent the complex numbers being added and the structure variable z to represent the result.

In the main function, we declare structure complex and variables x,y and z. Then we read two complex numbers from the keyboard, add them and print the result. The program is given below.

/* Addition of complex numbers: uses local structure definition */

#include <stdio.h>

int main ()


    struct complex {

       float re, im;

    } x, y, z;


    /* read complex numbers */

    printf("Enter real and imaginary parts of\n");

    printf(" complex number x: ");

    scanf("%f %f", &, &;

    printf(" complex number y: ");

    scanf("%f %f", &, &;

    /* add complex numbers */ = +; = +;

    /* print addition */

    printf(" = %4.2f = %4.2f\n",,;

    return 0;


       C Program to add of two complex numbers

About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.C.A, MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.