diff --git a/calculators/complex-number-calculator/index.html b/calculators/complex-number-calculator/index.html new file mode 100644 index 0000000..5c5be73 --- /dev/null +++ b/calculators/complex-number-calculator/index.html @@ -0,0 +1,30 @@ + + + + + Complex Number Calculator + + + +
+

Complex Number Calculator

+ + + + + + + + + + + + +
+

Result:

+

+
+
+ + + diff --git a/calculators/complex-number-calculator/script.js b/calculators/complex-number-calculator/script.js new file mode 100644 index 0000000..8d68d08 --- /dev/null +++ b/calculators/complex-number-calculator/script.js @@ -0,0 +1,62 @@ +document.getElementById("addButton").addEventListener("click", performAddition); +document.getElementById("subtractButton").addEventListener("click", performSubtraction); +document.getElementById("multiplyButton").addEventListener("click", performMultiplication); +document.getElementById("divideButton").addEventListener("click", performDivision); + +function getComplexNumber1() { + const real1 = parseFloat(document.getElementById("real1").value); + const imaginary1 = parseFloat(document.getElementById("imaginary1").value); + return { real: real1, imaginary: imaginary1 }; +} + +function getComplexNumber2() { + const real2 = parseFloat(document.getElementById("real2").value); + const imaginary2 = parseFloat(document.getElementById("imaginary2").value); + return { real: real2, imaginary: imaginary2 }; +} + +function performAddition() { + const complex1 = getComplexNumber1(); + const complex2 = getComplexNumber2(); + const result = { + real: complex1.real + complex2.real, + imaginary: complex1.imaginary + complex2.imaginary + }; + displayResult(result); +} + +function performSubtraction() { + const complex1 = getComplexNumber1(); + const complex2 = getComplexNumber2(); + const result = { + real: complex1.real - complex2.real, + imaginary: complex1.imaginary - complex2.imaginary + }; + displayResult(result); +} + +function performMultiplication() { + const complex1 = getComplexNumber1(); + const complex2 = getComplexNumber2(); + const result = { + real: complex1.real * complex2.real - complex1.imaginary * complex2.imaginary, + imaginary: complex1.real * complex2.imaginary + complex1.imaginary * complex2.real + }; + displayResult(result); +} + +function performDivision() { + const complex1 = getComplexNumber1(); + const complex2 = getComplexNumber2(); + const denominator = complex2.real * complex2.real + complex2.imaginary * complex2.imaginary; + const result = { + real: (complex1.real * complex2.real + complex1.imaginary * complex2.imaginary) / denominator, + imaginary: (complex1.imaginary * complex2.real - complex1.real * complex2.imaginary) / denominator + }; + displayResult(result); +} + +function displayResult(result) { + const resultText = `Result: ${result.real} + ${result.imaginary}i`; + document.getElementById("resultText").innerText = resultText; +} diff --git a/calculators/complex-number-calculator/style.css b/calculators/complex-number-calculator/style.css new file mode 100644 index 0000000..8e1e515 --- /dev/null +++ b/calculators/complex-number-calculator/style.css @@ -0,0 +1,60 @@ +body { + font-family: 'Arial', sans-serif; + background-color: #f0f0f0; + display: flex; + justify-content: center; + align-items: center; + height: 100vh; + margin: 0; +} + +.calculator { + background-color: #fff; + border-radius: 10px; + box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2); + padding: 20px; + text-align: center; + width: 300px; +} + +h1 { + color: #3498db; +} + +label, input, button { + width: 100%; + margin: 10px 0; + padding: 10px; + border: none; + border-radius: 5px; + font-size: 16px; + transition: background-color 0.3s, color 0.3s; +} + +label { + display: block; + text-align: left; + font-weight: bold; + color: #555; +} + +input { + display: block; + background-color: #f4f4f4; +} + +button { + background-color: #3498db; + color: #fff; + cursor: pointer; +} + +button:hover { + background-color: #2980b9; +} + +#resultText { + font-weight: bold; + font-size: 20px; + color: #333; +} diff --git a/index.html b/index.html index cbb7e18..6e93d2d 100644 --- a/index.html +++ b/index.html @@ -45,6 +45,7 @@

Calculators

Unit Convertor
Coordinate Distance Calculator
Cron Expression Calculator
+ Complex Number Calculator
SIP Calculator