SHARE
TWEET

Untitled

a guest Nov 12th, 2019 81 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2.  
  3. struct complex
  4. {
  5.     int real;
  6.     int imag;
  7. };
  8.  
  9.  
  10. typedef struct complex Complex;
  11.  
  12. Complex add(Complex A, Complex B){
  13.     Complex C;
  14.     C.real = A.real + B.real;
  15.     C.imag = A.imag + B.imag;
  16.     return C;
  17. }
  18.  
  19. Complex sub(Complex A, Complex B){
  20.     Complex C;
  21.     C.real = A.real - B.real;
  22.     C.imag = A.imag - B.imag;
  23.     return C;
  24. }
  25.  
  26. Complex mul(Complex A, Complex B){
  27.     Complex C;
  28.     C.real += A.real * B.real;
  29.     C.real += (A.imag * B.imag) * -1;
  30.     C.imag += A.real * B.imag;
  31.     C.imag += A.imag * B.real;
  32.     return C;
  33.  
  34. }
  35.  
  36.  
  37. int main()
  38. {
  39.     Complex A, B, C;
  40.  
  41.     char tmp;
  42.     int t;
  43.     scanf("%d\n",&t);
  44.     while(t--)
  45.     {
  46.         scanf("%c %d %d %d %d\n",&tmp,&A.real,&A.imag,&B.real,&B.imag);
  47.  
  48.         if(tmp == '+')
  49.             C = add(A,B);
  50.         else if(tmp == '-')
  51.             C = sub(A,B);
  52.         else if(tmp == '*')
  53.             C = mul(A,B);
  54.        
  55.         printf("%d %d\n",C.real,C.imag);
  56.     }
  57.  
  58.  
  59.     return 0;
  60. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top