-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbai5.cpp
More file actions
50 lines (48 loc) · 1.12 KB
/
bai5.cpp
File metadata and controls
50 lines (48 loc) · 1.12 KB
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
void print(const Complex &c)
{
if (c.a == 0 && c.b == 0)
{
cout << 0;
cout << endl;
return;
}
else if (c.a == 0 || c.b == 0)
{
if (c.a == 0)
{
if (c.b == 1)
cout << "i" << endl;
else
cout << "-" << "i" << endl;
}
else
cout << c.a << endl;
return;
}
else if (c.b == 1 || c.b == -1)
{
if (c.b == 1)
cout << c.a << "+" << "i" << endl;
else
cout << c.a << "-" << "i" << endl;
return;
}
if (c.b > 0)
cout << c.a << "+" << c.b << "i" << endl;
else if (c.b < 0)
cout << c.a << c.b << "i" << endl;
}
int compare(const Complex &c1, const Complex &c2)
{
if (c1.a * c1.a + c1.b * c1.b == c2.a * c2.a + c2.b * c2.b)
return 0;
if (c1.a * c1.a + c1.b * c1.b > c2.a * c2.a + c2.b * c2.b)
return 1;
if (c1.a * c1.a + c1.b * c1.b < c2.a * c2.a + c2.b * c2.b)
return -1;
}
Complex add(const Complex &c1, const Complex &c2)
{
Complex temp = {c1.a + c2.a, c1.b + c2.b};
return temp;
}