write a C# Program to Add Two Complex Numbers

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Collections;

using System.Threading;

using System.IO;


namespace CSharpProgram

{

    class AkbTechie

     {

        class Complex

        {

            public int real;

            public int imaginary;


            public Complex(int real, int imaginary)

            {

                this.real = real;

                this.imaginary = imaginary;

            }



            public static Complex operator +(Complex c1, Complex c2)

            {

                return new Complex(c1.real + c2.real, c1.imaginary + c2.imaginary);

            }



            public override string ToString()

            {

                return (String.Format("{0} + {1}i", real, imaginary));

            }

        }

            static void Main(string[] args)

           {


               Complex num1 = new Complex(3, 5);

               Complex num2 = new Complex(4, 6);

               Complex sum = num1 + num2;

               Console.WriteLine("First Complex Number is : "+num1);

               Console.WriteLine("Second Complex Number is : "+num2);

               Console.WriteLine("The Sum of the Two Complex Numbers is : "+sum);

               

               Console.ReadKey(); 

          }

    }

}


output:-

First Complex Number is : 3 + 5i

Second Complex Number is : 4 + 6i

The Sum of the Two Complex Numbers is : 7 + 11i


एक टिप्पणी भेजें

0 टिप्पणियाँ