Write a C program for addition of two complex numbers using structures.

 Write a C program for addition of two complex numbers using structures.

#include<stdio.h>
struct complex
{
float real;
float imag;
};
void main()
{
struct complex cnum1, cnum2, sum;
printf("Enter real and imaginary part of first complex number:\n");
scanf("%f%f",&cnum1.real,&cnum1.imag);
printf("Enter real and imaginary part of second complex number:\n");
scanf("%f%f",&cnum2.real,&cnum2.imag);
sum.real = cnum1.real + cnum2.real;
sum.imag = cnum1.imag + cnum2.imag;
printf("Sum=%0.2f+i%0.2f",sum.real, sum.imag);
}

Comments