forked from Sneha0008/hacktoberfest2022
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadd_complex.java
More file actions
37 lines (36 loc) · 751 Bytes
/
add_complex.java
File metadata and controls
37 lines (36 loc) · 751 Bytes
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
//add 2 complex nos
class complex{
double real;
double imag;
complex(){
real = imag = 0;
}
complex (double r, double i){
real = r;
imag = i;
}
complex sum (complex A, complex B){
complex temp = new complex();
temp.real = A.real + B.real;
temp.imag = A.imag + B.imag;
return temp;
}
//print the sum of complex numbers
void show()
{
System.out.println(real+ "+i" +imag);
}
}
class add_complex{
public static void main(String args[]){
complex c1 = new complex(3.0, 5.0);
complex c2 = new complex(3.0, 8.0);
complex c3 = c1.sum(c1, c2);
System.out.println("\n\n c1 = ");
c1.show();
System.out.println("c2 = ");
c2.show();
System.out.println("Sum = ");
c3.show();
}
}