Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //complex number
- using System;
- using System.CodeDom;
- using System.Collections.Generic;
- using System.Dynamic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Project_1
- {
- struct complex
- {
- public float real;
- public float imaginary;
- public complex(float real, float imaginary)
- {
- this.real = real;
- this.imaginary = imaginary;
- }
- public static complex operator +(complex a, complex b)
- {
- return new complex(a.real + b.real, a.imaginary + b.imaginary);
- }
- public static complex operator -(complex a, complex b)
- {
- return new complex(a.real - b.real, a.imaginary - b.imaginary);
- }
- public override string ToString()
- {
- return (String.Format("{0} + {1}i", real, imaginary));
- }
- }
- class Program
- {
- static void Main(string[] args)
- {
- complex c1 = new complex(3.0f, 5.0f);
- complex c2 = new complex(2.5f, 3.0f);
- complex c = c1 + c2;
- Console.WriteLine("Sum = {0}", c);
- Console.ReadLine();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement