forked from emh478/CS_Tools_305_Spring_23
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsomeCode.c
More file actions
84 lines (62 loc) · 1.31 KB
/
someCode.c
File metadata and controls
84 lines (62 loc) · 1.31 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/*
//#include <stdio.h>
typedef struct {
double real;
double imag;
} ComplexNumber;
void print_complex(const ComplexNumber c);
void acc_sum_complex(ComplexNumber *C, int N) {
// Type your code here.
}
int main() {
//initialize variables
int integerN;
scanf( "%d", integerN );
for ( int i = 0; i<integerN, i++ )
{
}
return 0;
}
void print_complex(const ComplexNumber c) {
if (c.imag >= 0.0)
printf("%.4f + %.4fi", c.real, c.imag);
else
printf("%.4f - %.4fi", c.real, -c.imag);
}
*/
#include <stdio.h>
typedef struct {
double real;
double imag;
} ComplexNumber;
void print_complex(const ComplexNumber c);
void acc_sum_complex(ComplexNumber *C, int N);
int main() {
int N;
scanf("%d", &N);
ComplexNumber C[N];
for (int i = 0; i < N; i++) {
scanf("%lf %lf", &C[i].real, &C[i].imag);
}
acc_sum_complex(C, N);
for (int i = 0; i < N; i++) {
print_complex(C[i]);
printf("\n");
}
return 0;
}
void print_complex(const ComplexNumber c) {
if (c.imag >= 0.0)
printf("%.4f + %.4fi", c.real, c.imag);
else
printf("%.4f - %.4fi", c.real, -c.imag);
}
void acc_sum_complex(ComplexNumber *C, int N) {
ComplexNumber sum = {0.0, 0.0};
for (int i = 0; i < N; i++) {
sum.real += C[i].real;
sum.imag += C[i].imag;
C[i].real = sum.real;
C[i].imag = sum.imag;
}
}