-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path04oct_exp7_1.c
66 lines (52 loc) · 1.12 KB
/
04oct_exp7_1.c
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include <stdio.h>
typedef struct
{
float real;
float imag;
} Complex;
Complex readComplex()
{
Complex c;
printf("Enter real part: ");
scanf("%f", &c.real);
printf("Enter imaginary part: ");
scanf("%f", &c.imag);
return c;
}
void writeComplex(Complex c)
{
printf("%.2f + %.2fi\n", c.real, c.imag);
}
Complex addComplex(Complex c1, Complex c2)
{
Complex result;
result.real = c1.real + c2.real;
result.imag = c1.imag + c2.imag;
return result;
}
Complex subComplex(Complex c1, Complex c2)
{
Complex result;
result.real = c1.real - c2.real;
result.imag = c1.imag - c2.imag;
return result;
}
int main()
{
Complex c1, c2, sum, diff;
printf("Enter first complex number - \n");
c1 = readComplex();
printf("Enter second complex number - \n");
c2 = readComplex();
sum = addComplex(c1, c2);
diff = subComplex(c1, c2);
printf("First complex number: ");
writeComplex(c1);
printf("Second complex number: ");
writeComplex(c2);
printf("Sum: ");
writeComplex(sum);
printf("Difference: ");
writeComplex(diff);
return 0;
}