forked from CPRO-Session1/Assignment6
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcomplex.c
More file actions
96 lines (92 loc) · 1.89 KB
/
complex.c
File metadata and controls
96 lines (92 loc) · 1.89 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
85
86
87
88
89
90
91
92
93
94
95
#include <stdio.h>
#include <math.h>
typedef struct{
float A1;
float B1;
float A2;
float B2;
}comp;
float addA(float a1, float a2){
float total;
total = a1+a2;
return total;
}
float addB(float b1,float b2){
float total;
total = b1+b2;
return total;
}
float subA(float a1, float a2){
float total;
total = a1-a2;
return total;
}
float subB(float b1,float b2){
float total;
total = b1-b2;
return total;
}
float multiplyReal(float a1, float a2, float b1, float b2){
float total;
total = a1*a2-b1*b2;
return total;
}
float multiplyImg(float a1,float a2,float b1,float b2){
float total;
total = a1*b2+a2*b1;
return total;
}
float divReal(float a1, float a2, float b1, float b2){
float total;
total = ((a1*b1)+(a2*b2))/((b1*b1)+(b2*b2));
return total;
}
float divImg(float a1, float a2, float b1, float b2){
float total;
total = ((a2*b1)-(a1*b2))/((b1*b1)+(b2*b2));
return total;
}
int main (){
int choice;
float a1,b1,a2,b2;
printf("enter you first A value\n");
scanf("%f",&a1);
printf("enter you first B value\n");
scanf("%f",&b1);
printf("enter you second A value\n");
scanf("%f",&a2);
printf("enter you second B value\n");
scanf("%f",&b2);
comp firstNum={a1,b1};
comp secondNum={a2,b2};
printf("Pick the operation (1 is +, 2 is -, 3 is *, 4 is /)\n");
scanf("%d", &choice);
if (choice==1)
{
printf("%f\n",addA(a1,a2));
printf("+\n");
printf("%f\n",addB(b1,b2));
printf("i\n");
}
if (choice==2)
{
printf("%f\n",subA(a1,a2));
printf("+\n");
printf("%f\n",subB(b1,b2));
printf("i\n");
}
if (choice==3)
{
printf("%f\n",multiplyReal(a1,b1,a2,b2));
printf("+\n");
printf("%f\n",multiplyImg(a1,a2,b1,b2));
printf("i\n");
}
if (choice==4)
{
printf("%f\n",divReal(a1,b1,a2,b2));
printf("+\n");
printf("%f\n",divImg(a1,a2,b1,b2));
printf("i\n");
}
}