Advertisement Remove all ads
Advertisement Remove all ads
Advertisement Remove all ads
Short Note
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.
Advertisement Remove all ads
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
Concept: Algorithm Design Techniques
Is there an error in this question or solution?