-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcomplex.c
More file actions
38 lines (32 loc) · 684 Bytes
/
complex.c
File metadata and controls
38 lines (32 loc) · 684 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include<stdio.h>
struct cadd {
int real;
int img;
}c1,c2;
typedef struct cadd add;
int main(){
int test,i;
scanf("%d",&test);
for(i=1;i<=test;i++){
char c;
scanf("%d%d",&c1.real,&c1.img);
scanf("%d%d %c",&c2.real,&c2.img,&c);
switch(c){
case '+':
printf("(%d)+(%d)i",c1.real+c2.real,c2.img+c1.img);
// if(c1.img + c2.img <= 0)
// printf("%d+%di",c1.real+c2.real,c2.img+c1.img);
break;
case '-':
printf("(%d)+(%d)i",c1.real-c2.real,c1.img-c2.img);
break;
case '*':
printf("(%d)+(%d)i",c1.real*c2.real-c1.img*c2.img,c1.real*c2.img+c1.img*c2.real);
break;
default:
printf("invalid");
}
printf("\n");
}
return 0;
}