Advertisement
Sabbir-bin

Add complex number

Apr 12th, 2020
251
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.47 KB | None | 0 0
  1. #include <stdio.h>
  2. struct complex
  3. {
  4.    int real, img;
  5. };
  6.  
  7. int main()
  8. {
  9.    struct complex p, q, r;
  10.  
  11.    printf("Enter p and q where (p + iq) is the first complex number.\n");
  12.    scanf("%d%d", &p.real, &p.img);
  13.    printf("Enter r and s where (r + is) is the second complex number.\n");
  14.    scanf("%d%d", &q.real, &q.img);
  15.  
  16.    r.real = p.real + q.real;
  17.    r.img = p.img + q.img;
  18.  
  19.    printf("Sum of the complex numbers: (%d) + (%di)\n", r.real, r.img);
  20.  
  21.    return 0;
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement