Tuesday, 27 November 2012

Complex Number

using System;
using System.Collections.Generic;
using System.Text;

namespace complex_number
{
class complex
{
int real,img;
public void getdata()
{
Console.WriteLine("Enter the Real Value");
real = int.Parse(Console.ReadLine());
Console.WriteLine("Enter the Imaginary Value");
img = int.Parse(Console.ReadLine());
}
public void display()
{
if (img > 0)
{
Console.WriteLine("complex No{0}+{1}i", real, img);
}
else
{
Console.WriteLine("complex No{0}{1}i", real, img);
}
}
public static complex operator +(complex t1, complex t2)
{
complex t4 = new complex();
t4.real = t1.real + t2.real;
t4.img = t1.img + t2.img;
return t4;
}



}
class comp
{
static void Main(string[] args)
{
complex t1 = new complex();
complex t2 = new complex();
complex t3 = new complex();
t1.getdata();
t1.display();
t2.getdata();
t2.display();
t3 = t1 + t2;
t3.display();
}
}
}

No comments:

Post a Comment