-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpractice.c
78 lines (67 loc) · 1.74 KB
/
practice.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
67
68
69
70
71
72
73
74
75
76
77
78
#include<stdio.h>
#include<stdlib.h>
typedef struct
{
float real,imag;
}complex;
typedef enum{
true,
false
}bool_enum;
complex sum(complex x,complex y);
complex min(complex x,complex y);
complex mult(complex x,complex y);
int main(){
complex cmp1,cmp2,add,sub,mul;
bool_enum i=true;
while(i==true){
int choice;
printf("enter choice:\n1.ADD \n2.SUB\n3.MUL\n");
scanf("%d",&choice);
if(choice==4){
break;
}else{
printf("\n Enter real and imag of 1st complex number");
scanf("%f %f",&cmp1.real,&cmp1.imag);
printf("\n Enter real and imag of 2nd complex number");
scanf("%f %f",&cmp2.real,&cmp2.imag);
switch (choice)
{
case 1:
add=sum(cmp1,cmp2);
printf("\n The addition of values is %.2f adn %.2fi\n",add.real,add.imag);
break;
case 2:
sub=min(cmp1,cmp2);
printf("\n The subtraction of values is %.2f adn %.2fi\n",sub.real,sub.imag);
break;
case 3:
mul=mult(cmp1,cmp2);
printf("\n The multiplication of values is %.2f adn %.2fi\n",mul.real,mul.imag);
break;
default:
printf("invalid input enter only between 1-4");
break;
}
}
}
return 0;
}
complex sum(complex x,complex y){
complex res;
res.real=x.real+y.real;
res.imag=x.imag+y.imag;
return res;
}
complex min(complex x, complex y){
complex res;
res.real=x.real-y.real;
res.imag=x.imag-y.imag;
return res;
}
complex mult(complex x,complex y){
complex res;
res.real=x.real*y.real-x.imag*y.imag;
res.imag=x.real*y.imag+y.real*x.imag;
return res;
}