Advertisement
ZazoTazo

Lab6-1

Nov 11th, 2020
718
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.21 KB | None | 0 0
  1. //complex number
  2. using System;
  3. using System.CodeDom;
  4. using System.Collections.Generic;
  5. using System.Dynamic;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9.  
  10. namespace Project_1
  11. {
  12.     struct complex
  13.     {
  14.         public float real;
  15.         public float imaginary;
  16.  
  17.         public complex(float real, float imaginary)
  18.         {
  19.             this.real = real;
  20.             this.imaginary = imaginary;
  21.         }
  22.  
  23.         public static complex operator +(complex a, complex b)
  24.         {
  25.             return new complex(a.real + b.real, a.imaginary + b.imaginary);
  26.         }
  27.         public static complex operator -(complex a, complex b)
  28.         {
  29.             return new complex(a.real - b.real, a.imaginary - b.imaginary);
  30.         }
  31.  
  32.         public override string ToString()
  33.         {
  34.             return (String.Format("{0} + {1}i", real, imaginary));
  35.         }
  36.     }
  37.  
  38.     class Program
  39.     {
  40.         static void Main(string[] args)
  41.         {
  42.             complex c1 = new complex(3.0f, 5.0f);
  43.             complex c2 = new complex(2.5f, 3.0f);
  44.  
  45.             complex c = c1 + c2;
  46.             Console.WriteLine("Sum = {0}", c);
  47.             Console.ReadLine();
  48.         }
  49.     }
  50. }
  51.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement