NCERT Solutions Class 11, Computer Science, Chapter- 4, Introduction to Problem Solving
1. Write pseudocode that reads two numbers and divide one by another and display the quotient.
Solution:
Input first number
Input second number
Calculate quotient = first number // second number
Print quotient
2. Two friends decide who gets the last slice of a cake by flipping a coin five times. The first person to win three flips wins the cake. An input of 1 means player 1 wins a flip, and a 2 means player 2 wins a flip. Design an algorithm to determine who takes the cake?
Solution:
Set player1 = 0
Set player2 = 0
For i in range (5):
Input coin number
If coin = 1 then
Player1 += 1
Elif coin = then
Player2 += 1
If player1 > 2 then
Player1 wins
Elif player2 > 2 then
Player2 wins
3. Write the pseudocode to print all multiples of 5 between 10 and 25 (including both 10 and 25).
Solution:
For i in range ( 10, 26, 5 ):
Print i
4. Give an example of a loop that is to be executed a certain number of times.
Solution:
For i in range (10, 26, 5)
It will execute only 3 times.
5. Suppose you are collecting money for something. You need Rs. 200 in all. You ask your parents, uncles and aunts as well as grandparents. Different people may give either Rs. 10, Rs. 20 or even Rs. 50. You will collect till the total becomes 200. Write the algorithm.
Solution:
Set sum = 0
While sum = 200
Input money obtained
Sum += money
Print thank you
Algorithm:
1 - Start
2 - Approach to parents, uncle, aunts, and grandparents
3 - Request for money
4 - Collect the given amount
5 - Add the amount received to make sure it is 200
6 - If not reach 200
7 - Again, request from others
8 - If received 200 goals achieved
9 - Stop
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 in the total bill.
Solution:
Input Price
Input quantity
Calculate total = price * quantity
Calculate including_GST = total + total*0.05
Print total bill is including_GST
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
Solution:
Input marks of computer science
Input marks of mathematics
Input marks of physics
Calculate sum = CS + math + phy
Calculate percentage = ( sum / 300 ) * 100
Print sum
Print percentage
8. Write an algorithm to find the greatest among two different numbers entered by the user.
Solution:
Input first number
Input second number
If first > second then
Print first number is greater then second
else :
Print second number is greater than first
9. Write an algorithm that performs the following: Ask a user to enter a number. If the number is between 5 and 15, write the word GREEN. If the number is between 15 and 25, write the word BLUE. if the number is between 25 and 35, write the word ORANGE. If it is any other number, write that ALL COLOURS ARE BEAUTIFUL.
Solution:
Input number
If 5 < number < 15 then
Print GREEN
elif 15 < number < 25then
Print BLUE
elif 25 < number < 35 then
Print ORANGE
else :
Print ALL COLOURS ARE BEAUTIFUL.
10. Write an algorithm that accepts four numbers as input and find the largest and smallest of them.
Solution:
Input first number
Input second number
Input third number
Input fourth number
Set lst = [ first , second, third , fourth ]
Sort the lst
lst.sort( )
Print greatest number is lst [ -1 ]
Print smallest number is lst [ 0 ]