Advertisements
Advertisements
Question
For some calculations, we want an algorithm that accepts only positive integers up to 100.
Accept_1 to 100_Algo
INPUT Number
IF (0 <= Number) AND (Number <= 100)
ACCEPT
Else
REJECT
- On what values will this algorithm fail?
- Can you improve the algorithm?
Short/Brief Note
Advertisements
Solution
If we enter 0 then this algorithm will fail.
Correct algorithm:
INPUT Number
IF (0 < Number) AND (Number <= 100)
ACCEPT
Else
REJECTshaalaa.com
Representation of Algorithms
Is there an error in this question or solution?
