{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

cp13_14_ps11_sol

# cp13_14_ps11_sol - Home Work 11 The problems in this...

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

Home Work 11 The problems in this problem set cover lectures C13 and C14 1. a. Define a robust algorithm to carry out integer division using repeated subtraction. Your algorithm accepts two integers and returns the quotient and the remainder. Hint: What are the preconditions and postconditions of your algorithm? Precondtions: Two integers x , y y is non-zero Algorithm: Set R to absolute_value( x ) Set Q to zero While R >= absolute_value ( y ) Increment Q R := R- absolute_value( y ) If either x or y are negative If both x and y are negative Set R to –R else if x is negative Set R to –R Set Q to –Q Display Q and R Postconditions: Q contains the quotient R contains the remainder x = Q* y + R, abs(R) < abs(Q)

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

View Full Document
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 b. Implement your algorithm as an Ada95 program, using exception handling to provide robustness. . ---------------------------------------------------------
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 5

cp13_14_ps11_sol - Home Work 11 The problems in this...

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

View Full Document
Ask a homework question - tutors are online