This preview shows pages 1–2. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: 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 users 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 for3 for multiplication and 4 for division....
View
Full
Document
 Summer '08
 Staff

Click to edit the document details