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
| #include <stdio.h>
typedef struct kompleksno {
double re;
double im;
} cplx;
cplx vsota(cplx x, cplx y) {
cplx rezultat;
rezultat.re = x.re + y.re;
rezultat.im = x.im + y.im;
return rezultat;
}
cplx produkt(cplx x, cplx y) {
cplx rezultat;
rezultat.re = x.re * y.re - x.im * y.im;
rezultat.im = x.re * y.im + x.im * y.re;
return rezultat;
}
main() {
cplx w, z, p, v;
w.re = 3; w.im=2;
z.re = 5; z.im=7;
v = vsota(w,z);
p = produkt(w,z);
printf("(%.f + %.f i) + (%.f + %.f i) = %.f + %.f i\n",
w.re, w.im, z.re, z.im, v.re, v.im);
printf("(%.f + %.f i) * (%.f + %.f i) = %.f + %.f i\n",
w.re, w.im, z.re, z.im, p.re, p.im);
}
|