본문 바로가기
C#/0x22-other

[c#] 복소수 사칙연산

by SpeeDr00t 2023. 4. 6.
반응형
using System;
using System.Numerics;
class Program
{
static void Main()
{
// 복소수 생성
Complex c1 = new Complex(2, 3); // 2 + 3i
Complex c2 = new Complex(4, -2); // 4 - 2i
// 복소수 사칙연산
Complex sum = c1 + c2; // 6 + 1i
Complex difference = c1 - c2; // -2 + 5i
Complex product = c1 * c2; // 14 + 8i
Complex division = c1 / c2; // 0.3 + 0.7i
// 복소수 출력
Console.WriteLine("c1: " + c1);
Console.WriteLine("c2: " + c2);
Console.WriteLine("Sum: " + sum);
Console.WriteLine("Difference: " + difference);
Console.WriteLine("Product: " + product);
Console.WriteLine("Division: " + division);
}
}
view raw Complex.cs hosted with ❤ by GitHub
반응형