JavaScript: Subtract two complex numbers
JavaScript Math: Exercise-51 with Solution
Subtract Complex Numbers
Write a JavaScript program to subtract two complex numbers.
A complex number is a number that can be expressed in the form a + bi, where a and b are real numbers and i is the imaginary unit, that satisfies the equation i2 = −1. In this expression, a is the real part and b is the imaginary part of the complex number.
Sample Solution:
JavaScript Code:
Output:
-2-10i
Flowchart:

Live Demo:
For more Practice: Solve these Related Problems:
- Write a JavaScript function that subtracts two complex numbers represented as objects with properties for real and imaginary parts.
- Write a JavaScript function that subtracts complex numbers by converting them to polar coordinates and then back to rectangular form.
- Write a JavaScript function that validates complex number inputs and performs subtraction, returning the result as a formatted string.
- Write a JavaScript function that subtracts two complex numbers and handles edge cases, such as when one of the numbers is zero.
Improve this sample solution and post your code through Disqus.
Previous: Write a JavaScript program to add two complex numbers.
Next: Write a JavaScript program to multiply two complex numbers.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.