//A Java Program For Multiplication of two complex numbers
class Complex
{
double real;
double imag;
Complex()
{
real = 4.0;
imag = 5.0;
}
Complex(double r, double i)
{
real = r;
imag = i;
}
void show()
{
System.out.println("Complex Number is ("+real+" + i "+imag+")");
}
Complex multiply(Complex x, Complex y)
{
Complex Mul = new Complex();
Mul.real = x.real*y.real - x.imag*y.imag;
Mul.imag = x.real*y.imag + x.imag*y.real;
return Mul;
}
}
class Operation
{
public static void main(String args[])
{
Complex a = new Complex();
Complex b = new Complex(7.0,8.2);
Complex c = new Complex();
a.show();
b.show();
c = c.multiply(a,b);
c.show();
}
}
class Complex
{
double real;
double imag;
Complex()
{
real = 4.0;
imag = 5.0;
}
Complex(double r, double i)
{
real = r;
imag = i;
}
void show()
{
System.out.println("Complex Number is ("+real+" + i "+imag+")");
}
Complex multiply(Complex x, Complex y)
{
Complex Mul = new Complex();
Mul.real = x.real*y.real - x.imag*y.imag;
Mul.imag = x.real*y.imag + x.imag*y.real;
return Mul;
}
}
class Operation
{
public static void main(String args[])
{
Complex a = new Complex();
Complex b = new Complex(7.0,8.2);
Complex c = new Complex();
a.show();
b.show();
c = c.multiply(a,b);
c.show();
}
}
No comments:
Post a Comment