forked from srinirad/pps-IA1-practice
-
Notifications
You must be signed in to change notification settings - Fork 0
/
p8original.c
53 lines (48 loc) · 841 Bytes
/
p8original.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
#include<stdio.h>
typedef struct complex
{
float real,imaginary;
}
complex;
int get_n()
{
int n;
printf("how many complex numbers?\n");
scanf("%d",&n);
return n;
}
void input(int n , complex a[n])
{
for(int i=0;i<n;i++)
{
printf("enter real part");
scanf("%f",&a[i].real);
printf("enter imaginary part");
scanf("%f",&a[i].imaginary);
}
}
complex add(int n,complex a[n])
{
complex m;
m.real=0;m.imaginary=0;
for(int i=0;i<n;i++)
{
m.real=m.real+a[i].real;
m.imaginary=m.imaginary+a[i].imaginary;
}
return m;
}
void output(int n,complex a[n],complex result)
{
printf("sum is %f+%fi",result.real,result.imaginary);
}
int main()
{
int n;
n= get_n();
complex a[100],result;
input(n,a);
result=add(n,a);
output(n,a,result);
return 0;
}