-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLab4-3.c
More file actions
52 lines (47 loc) · 888 Bytes
/
Lab4-3.c
File metadata and controls
52 lines (47 loc) · 888 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
typedef struct complex{
int real;
int img;
}COMPLEX;
void print_complex(struct complex* x) {
if (x->img > 0) {
printf("(%d + %di)", x->real, x->img);
}
//0이 나오는 케이스
//1이 나오는 케이스
else {
printf("(%d - %di)", x->real, x->img*(-1));
}
}
COMPLEX add(COMPLEX x, COMPLEX y) {
COMPLEX z;
z.real = x.real + y.real;
z.img = x.img + y.img;
return z;
}
COMPLEX sub(COMPLEX x, COMPLEX y) {
COMPLEX z;
z.real = x.real - y.real;
z.img = x.img - y.img;
return z;
}
void main() {
COMPLEX x, y, z;
scanf("%d %d", &x.real, &x.img);
scanf("%d %d", &y.real, &y.img);
z = add(x, y);
print_complex(&x);
printf(" + ");
print_complex(&y);
printf(" = ");
print_complex(&z);
printf("\n");
z = sub(x, y);
print_complex(&x);
printf(" - ");
print_complex(&y);
printf(" = ");
print_complex(&z);
printf("\n");
}