Complex number calculator create a complex number


C programming

Complex Number Calculator

Create a complex number calculator (For a brief overview on complex numbers, take a look at https://mathworld. wolfram.com/ComplexNumber.html). Your calculator should be able to compute the following:

  • Addition of two complex numbers: z1 + z2
  • Subtraction of two complex numbers: z1 - z2
  • Multiplication of two numbers: z1 z2
  • Division of two complex numbers: z1 z2
  • Computation of the magnitude and phase (in degrees) of a complex number z. 1

The program should ask the user which of the five operations he wants to perform. It then asks the user to enter the appropriate values for the complex numbers and performs the necessary computation. Your program should execute continuously until the user requests to terminate it.

Sample run:

Press + for addition, - for subtraction, * for multiplication, / for division, m for magnitude and phase, or any other key to exit: +

Enter a complex number: 2 5

Enter a complex number: 1 8

(2+5i)+(1+8i)=(3+13i)

Press + for addition, - for subtraction, * for multiplication, / for division, m for magnitude and phase, or any other key to exit: n

Your program should include the following functions:

1. Void read complex(float *z r, float *z i) // reads a complex number from the keyboard

2. Void print complex(float z r, float z i) // prints a float number on the screen in the form a+bi

3. Void add complex(float z1 r, float z1 i, float z2 r, float z2 i, float *z3 r, float *z3 i) // z3=z1+z2

4. Void sub complex(float z1 r, float z1 i, float z2 r, float z2 i, float *z3 r, float *z3 i) // z3=z2-z1

5. Void mul complex(float z1 r, float z1 i, float z2 r, float z2 i, float *z3 r, float *z3 i) // z3=z1· z2

6. Void div complex(float z1 r, float z1 i, float z2 r, float z2 i, float *z3 r, float *z3 i) // z3=z1 z2

7. Void par complex(float z1 r, float z1 i, float *mag, float *ph) // magnitude and phase

Solution Preview :

Prepared by a verified Expert
Basic Computer Science: Complex number calculator create a complex number
Reference No:- TGS02203228

Now Priced at $35 (50% Discount)

Recommended (96%)

Rated (4.8/5)