SUBTRACTION OF TWO COMPLEX NUMBERS

#include <stdio.h>
struct complex
{
int r, i;
};
int main()
{
struct complex a, b, c;
printf("Enter the value a and b of the first complex number (a + ib): ");
scanf("%d%d", &a.r, &a.i);
printf("Enter the value c and d of the second complex number (c + id): ");
scanf("%d%d", &b.r, &b.i);
c.r = a.r - b.r;
c.i = a.i - b.i;
if (c.i >= 0)
printf("Difference of the complex numbers = %d + %di", c.r, c.i);
else
printf("Difference of the complex numbers = %d %di", c.r, c.i);
return 0;
}

Output:

Enter the value a and b of the first complex number (a + ib): 2 3
Enter the value c and d of the second complex number (c + id): 4 5
Difference of the complex numbers = -2 -2i

  

Comments

Popular posts from this blog

C program to copy the contents of one file to another

Division of two complex numbers

Student marks by using structures