English

Exchange the contents: Given two glasses marked A and B. Glass A is full of apple drink and glass B is full of grape drink. For exchanging the contents of glasses A and B, represent

Advertisements

Question

Exchange the contents: Given two glasses marked A and B. Glass A is full of apple drink and glass B is full of grape drink. For exchanging the contents of glasses A and B, represent the state by suitable variables, and write the specification of the algorithm.

Short/Brief Note
Advertisements

Solution

The specification of the algorithm:
exchange (A, B)
–inputs: A, B are real and >0
–outputs: A, B are real and >0
State representation
TEMP:=A
A:=B
B:= TEMP

shaalaa.com
Algorithm Design Techniques
  Is there an error in this question or solution?
Chapter 6: Specification and Abstraction - Evaluation - Section - D [Page 87]
Advertisements
Share
Notifications



      Forgot password?
Use app×