CGC_Codes

C# Complex numbers

Jan 30th, 2017
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.79 KB | None | 0 0
  1. using System;
  2. public struct Complex
  3. {
  4.     public int real;
  5.     public int imaginary;
  6.    
  7.     public Complex(int real, int imaginary)
  8.     {
  9.         this.real = real;
  10.         this.imaginary = imaginary;
  11.     }
  12.    
  13.    
  14.     public static Complex operator +(Complex c1,
  15.     {
  16.         return new Complex(c1.real + c2.real, c1.
  17.     }
  18.    
  19.    
  20.     public override string ToString()
  21.     {
  22.         return (Stream.Format("{0} + {1}i", real,
  23.     }
  24. }
  25.  
  26.  
  27. class TextComplex
  28. {
  29.     static void Main()
  30.     {
  31.                 Complex num1 = new Complex(2, 3);
  32.  
  33.         Complex num2 = new Complex(3, 4);
  34.  
  35.         Complex sum = num1 + num2;
  36.  
  37.         Console.WriteLine("First Complex Number :  {0}", num1);
  38.  
  39.         Console.WriteLine("Second Complex Number : {0}", num2);
  40.  
  41.         Console.WriteLine("The Sum of the Two Numbers : {0}", sum);
  42.  
  43.         Console.ReadLine();
  44.     }
  45. }
Add Comment
Please, Sign In to add comment