pset11_sol_04

# pset11_sol_04 - Home Work 11 The problems in this problem...

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. . ---------------------------------------------------------² . -- Procedure to carry out robust division² . -- Programmer: Jayakanth Srinivasan² . -- Date Last Modified : April 17,2004² . ---------------------------------------------------------² . with Ada.Text_Io;² . with Ada.Integer_Text_Io;² . use Ada.Text_Io;² . use Ada.Integer_Text_Io;²
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 9

pset11_sol_04 - Home Work 11 The problems in this problem...

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

View Full Document
Ask a homework question - tutors are online