{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

homework2

# homework2 - Programming Using C Homework 2 1 Write a simple...

This preview shows pages 1–2. Sign up to view the full content.

Programming Using C Homework 2 1. Write a simple calculator program for complex numbers. Each complex number can be seen as a point in R 2 , written as a + bi , where a, b R are the real and imaginary parts and i = - 1 is the unitary imaginary number. To add and subtract two complex numbers, add or subtract respectively their real and imaginary parts, i.e., ( a + bi ) + ( c + di ) = ( a + c ) + ( b + d ) i . To multiply, use the distributivity rule, obtaining ( a + bi )( c + di ) = ( ac - bd ) + ( ad + bc ) i . Finally, to divide, amplify the fraction such that the denominator becomes a real number: a + bi c + di = ( a + bi )( c - di ) ( c + di )( c - di ) = bd + ac c 2 + d 2 + cb - ad c 2 + d 2 i . The program will work in a loop that presents a menu of choices, waits for the user’s choice, accepts two complex numbers, carries out the computation and prints the result. The menu choices are: 0 for exiting the program, 1 for addition, 2 for subtraction, 3 for multiplication and 4 for division. The program should check for division by 0 + 0 i , which is undefined.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 3

homework2 - Programming Using C Homework 2 1 Write a simple...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online