Page 125 - Computer Science V2.0 Class 11
P. 125
Ans. i ← 1, player1 ← 0, player2 ← 0
while i <= 5 do
input coin
if coin = 1 then
player1 ← player1 + 1
else
player2 ← player2 + 1
end if
if player1 = 3 then
print "Player 1 won the last slice"
break out of the loop
end if
if player2 = 3 then
print "Player 2 won the last slice"
break out of the loop
end if
i ← i + 1
end-while
3. Write the pseudocode to print all multiples of 5 between 10 and 25 (including both 10 and 25).
Ans. for i = 10 to 15 do
if i % 5 = 0 then
print i
end-for
4. Give an example of a loop that is to be executed a certain number of times.
Ans. Suppose we want to execute a for loop five times. The loop structure will be as follows:
for i = 1 to 5 do
print i
end-for
5. Suppose you are collecting money for something. You need 200 in all. You ask your parents, uncles, aunts, and grandparents. Different
people may give either 10, 20, or even 50. You will collect until the total reaches 200. Write the algorithm.
Ans. totalMoney ← 0
while totalMoney < 200 do
input money
totalMoney ← totalMoney + money
end-while
6. Write the pseudocode to print the bill depending upon the price and quantity of an item. Also print Bill GST, which is the bill after adding
5% of tax to the total bill.
Ans. input totalItem
input pricePerItem
billAmount ← totalItem * pricePerItem
print billAmount
taxAmount ← billAmount * (5 / 100)
gstBillAmount ← billAmount + taxAmount
print gstBillAmount
7. Write pseudocode that will perform the following:
a. Read the marks of three subjects: Computer Science, Mathematics and Physics, out of 100
b. Calculate the aggregate marks
c. Calculate the percentage of marks
Problem Solving 111

