Page 129 - Computer Science V2.0 Class 11
P. 129
Ans. The given algorithm seems correct for the most part, but there is a small issue in the conditions. The condition Number < 9 is checking
for numbers less than 9, which includes all single-digit numbers. However, it doesn’t cover the case when the number is equal to 9. We
need to adjust the conditions to include equality as well. Also, the condition Number < 99 covers two-digit numbers, but it doesn’t
include 99. For the above given algorithm the input 9 and 99 will give wrong output. For input 9 the above algorithm will give ‘Double
Digit’ as the condition for a single digit written as Number < 9.
Same for 99 the above algorithm will give ‘Big’ as the condition for double digit written as Number < 99.
Correct algorithm:
input Number
if Number < 10 then
print "Single Digit"
else if Number < 100
print "Double Digit"
else
print "Big"
18. For some calculations, we want an algorithm that accepts only positive integers from 1 to 100.
Accept_1to100_Algo
INPUT Number
IF (0<= Number) AND (Number <= 100)
ACCEPT
Else
REJECT
a) On what values will this algorithm fail?
b) Can you improve the algorithm?
Ans. a) The algorithm will fail for the value 0. Since the if a condition is true if the value of the NUMBER is 0 it will accept the input. But the
algorithm is supposed to accept numbers between 1 and 100 only.
b) Can you improve the algorithm?
Correct algorithm:
input Number
if (0<Number) AND (Number <= 100) then
ACCEPT
else
REJECT
Answers
Multiple Choice Questions
1. (b) 2. (c) 3. (d) 4. (c) 5. (b)
True or False
1. (T) 2. (T) 3. (F) 4. (F) 5. (T) 6. (F)
Fill in the blanks
1. bugs 2. flowchart 3. source code 4. machine code/ object code
5. Debugging
Problem Solving 115

