C program to add two complex numbers


SUBMITTED BY: Guest

DATE: Jan. 21, 2014, 11:10 p.m.

FORMAT: Text only

SIZE: 785 Bytes

HITS: 774

  1. #include <stdio.h>
  2. struct complex
  3. {
  4. int real, img;
  5. };
  6. int main()
  7. {
  8. struct complex a, b, c;
  9. printf("Enter a and b where a + ib is the first complex number.\n");
  10. printf("a = ");
  11. scanf("%d", &a.real);
  12. printf("b = ");
  13. scanf("%d", &a.img);
  14. printf("Enter c and d where c + id is the second complex number.\n");
  15. printf("c = ");
  16. scanf("%d", &b.real);
  17. printf("d = ");
  18. scanf("%d", &b.img);
  19. c.real = a.real + b.real;
  20. c.img = a.img + b.img;
  21. if ( c.img >= 0 )
  22. printf("Sum of two complex numbers = %d + %di\n",c.real,c.img);
  23. else
  24. printf("Sum of two complex numbers = %d %di\n",c.real,c.img);
  25. return 0;
  26. }

comments powered by Disqus