Introduction to Problem Solving

This page contains the NCERT Computer Science class 11 chapter 4 Introduction to Problem Solving. You can find the solutions for the chapter 4 of NCERT class 11 Computer Science Exercise. So is the case if you are looking for NCERT class 11 Computer Science related topic Introduction to Problem Solving questions and answers for the Exercise
Exercise
1. Write pseudocode that reads two numbers and divide one by another and display the quotient.
Pseudocode:
STEP 1: PRINT "Enter first number (dividend)"
STEP 2: INPUT a
STEP 3: PRINT "Enter second number (divisor)"
STEP 4: INPUT b

STEP 5: IF b == 0 THEN
STEP 6:     PRINT "Division not possible (divisor is 0)"
STEP 7: ELSE
STEP 8:     COMPUTE q = a / b
STEP 9:     PRINT "Quotient =", q
STEP 10: END IF
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?
Algorithm (with counters):
STEP 1: SET p1 = 0, p2 = 0
STEP 2: SET flip = 1

STEP 3: WHILE flip <= 5 AND p1 < 3 AND p2 < 3 DO
STEP 4:     PRINT "Enter winner of flip (1 or 2)"
STEP 5:     INPUT x

STEP 6:     IF x == 1 THEN
STEP 7:         INCREMENT p1
STEP 8:     ELSE IF x == 2 THEN
STEP 9:         INCREMENT p2
STEP 10:    ELSE
STEP 11:        PRINT "Invalid input, enter 1 or 2"
STEP 12:        DECREMENT flip   // so this flip is re-entered
STEP 13:    END IF

STEP 14:    INCREMENT flip
STEP 15: END WHILE

STEP 16: IF p1 == 3 THEN
STEP 17:     PRINT "Player 1 wins the cake"
STEP 18: ELSE
STEP 19:     PRINT "Player 2 wins the cake"
STEP 20: END IF
3. Write the pseudocode to print all multiples of 5 between 10 and 25 (including both 10 and 25).
Pseudocode:
STEP 1: SET n = 10
STEP 2: WHILE n <= 25 DO
STEP 3:     IF n MOD 5 == 0 THEN
STEP 4:         PRINT n
STEP 5:     END IF
STEP 6:     INCREMENT n
STEP 7: END WHILE
4. Give an example of a loop that is to be executed a certain number of times.
Example (print “Hello” 5 times):
STEP 1: SET count = 1
STEP 2: WHILE count <= 5 DO
STEP 3:     PRINT "Hello"
STEP 4:     INCREMENT count
STEP 5: END WHILE
5. Suppose you are collecting money for something. You need ₹ 200 in all. You ask your parents, uncles and aunts as well as grandparents. Different people may give either ₹ 10, ₹ 20 or even ₹ 50. You will collect till the total becomes 200. Write the algorithm.
Algorithm:
STEP 1: SET total = 0

STEP 2: WHILE total < 200 DO
STEP 3:     PRINT "Enter amount received (10/20/50)"
STEP 4:     INPUT amt

STEP 5:     IF amt == 10 OR amt == 20 OR amt == 50 THEN
STEP 6:         total = total + amt
STEP 7:         PRINT "Total collected =", total
STEP 8:     ELSE
STEP 9:         PRINT "Invalid amount"
STEP 10:    END IF
STEP 11: END WHILE

STEP 12: PRINT "Target reached. Total =", total
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.
Pseudocode:
STEP 1: PRINT "Enter price"
STEP 2: INPUT price
STEP 3: PRINT "Enter quantity"
STEP 4: INPUT qty

STEP 5: COMPUTE bill = price * qty
STEP 6: COMPUTE gst = 0.05 * bill
STEP 7: COMPUTE billGST = bill + gst

STEP 8: PRINT "Bill (without GST) =", bill
STEP 9: PRINT "GST (5%) =", gst
STEP 10: PRINT "Bill GST =", billGST
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
Pseudocode:
STEP 1: INPUT cs
STEP 2: INPUT maths
STEP 3: INPUT physics

STEP 4: COMPUTE aggregate = cs + maths + physics
STEP 5: COMPUTE percentage = (aggregate / 300) * 100

STEP 6: PRINT "Aggregate =", aggregate
STEP 7: PRINT "Percentage =", percentage
8. Write an algorithm to find the greatest among two different numbers entered by the user.
Algorithm:
STEP 1: INPUT a
STEP 2: INPUT b

STEP 3: IF a > b THEN
STEP 4:     PRINT "Greatest =", a
STEP 5: ELSE
STEP 6:     PRINT "Greatest =", b
STEP 7: END IF
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.
Algorithm (no overlap using else-if order):
STEP 1: INPUT n

STEP 2: IF n >= 5 AND n < 15 THEN
STEP 3:     PRINT "GREEN"
STEP 4: ELSE IF n >= 15 AND n < 25 THEN
STEP 5:     PRINT "BLUE"
STEP 6: ELSE IF n >= 25 AND n <= 35 THEN
STEP 7:     PRINT "ORANGE"
STEP 8: ELSE
STEP 9:     PRINT "ALL COLOURS ARE BEAUTIFUL"
STEP 10: END IF
10. Write an algorithm that accepts four numbers as input and find the largest and smallest of them.
Algorithm:
STEP 1: INPUT a, b, c, d

STEP 2: SET largest = a
STEP 3: SET smallest = a

STEP 4: IF b > largest THEN largest = b
STEP 5: IF c > largest THEN largest = c
STEP 6: IF d > largest THEN largest = d

STEP 7: IF b < smallest THEN smallest = b
STEP 8: IF c < smallest THEN smallest = c
STEP 9: IF d < smallest THEN smallest = d

STEP 10: PRINT "Largest =", largest
STEP 11: PRINT "Smallest =", smallest
11. Write an algorithm to display the total water bill charges of the month depending upon the number of units consumed by the customer as per the following criteria:
for the first 100 units @ 5 per unit
for next 150 units @ 10 per unit
more than 250 units @ 20 per unit

Also add meter charges of 75 per month to calculate the total water bill .
Algorithm:
STEP 1: INPUT units
STEP 2: SET charge = 0

STEP 3: IF units <= 100 THEN
STEP 4:     charge = units * 5
STEP 5: ELSE IF units <= 250 THEN
STEP 6:     charge = (100 * 5) + ((units - 100) * 10)
STEP 7: ELSE
STEP 8:     charge = (100 * 5) + (150 * 10) + ((units - 250) * 20)
STEP 9: END IF

STEP 10: COMPUTE totalBill = charge + 75
STEP 11: PRINT "Total Water Bill =", totalBill
12. What are conditionals? When they are required in a program?
Conditionals are used to check possibilities and take decisions based on true/false (binary) values. The program checks one or more conditions and performs actions depending on whether the condition is true or false.
They are required when a program has to do decision making / selection, like “IF age ≥ 18 then eligible else not eligible”. Also, in code, “otherwise” is written using ELSE (if-else).
13. Match the pairs
Flowchart Symbol
Functions
Flow of Control
Process Step
Start/Stop of the Process
Data
Decision Making

Matches:
Flowchart Symbol
Functions
Start/Stop of the Process
Data
Process Step
Decision Making
Flow of control
14. Following is an algorithm for going to school or college. Can you suggest improvements in this to include other options?
Reach_School_Algorithm
a)
Wake up
b)
Get ready
c)
Take lunch box
d)
Take bus
e)
Get off the bus
f)
Reach school or college
Improved algorithm (with decision making):
STEP 1: Wake up
STEP 2: Get ready
STEP 3: Take lunch box

STEP 4: PRINT "Is it raining? (YES/NO)"
STEP 5: INPUT rain

STEP 6: IF rain == "YES" THEN
STEP 7:     PRINT "Take umbrella/raincoat"
STEP 8: END IF

STEP 9: PRINT "Choose transport: 1-Walk 2-Bus 3-Auto/Car"
STEP 10: INPUT choice

STEP 11: IF choice == 1 THEN
STEP 12:     Walk to school/college
STEP 13: ELSE IF choice == 2 THEN
STEP 14:     Go to bus stop
STEP 15:     Wait for bus
STEP 16:     Take bus
STEP 17:     Get off at stop
STEP 18: ELSE
STEP 19:     Book auto/car
STEP 20:     Travel to school/college
STEP 21: END IF

STEP 22: Reach school/college
15. Write a pseudocode to calculate the factorial of a number (Hint: Factorial of 5, written as 5! = 5 × 4 × 3 × 2 × 1).
Pseudocode:
STEP 1: INPUT n
STEP 2: SET fact = 1
STEP 3: SET i = 1

STEP 4: WHILE i <= n DO
STEP 5:     fact = fact * i
STEP 6:     INCREMENT i
STEP 7: END WHILE

STEP 8: PRINT "Factorial =", fact
16. Draw a flowchart to check whether a given number is an Armstrong number. An Armstrong number of three digits is an integer such that the sum of the cubes of its digits is equal to the number itself. For example, 371 is an Armstrong number since 3**3 + 7**3 + 1**3 = 371.
Flowchart steps (text form):
STEP 1:
Start
STEP 2:
Input num
STEP 3:
Set original = num, sum = 0
STEP 4:
While num > 0
digit = num MOD 10
sum = sum + (digit * digit * digit)
num = num DIV 10
STEP 5:
Decision: Is sum == original?
Yes → Print “Armstrong number”
No → Print “Not Armstrong”
STEP 6:
Stop
Flowchart to check whether a given number is an Armstrong number Start Input num Set original = num, sum = 0 num > 0? Yes digit = num MOD 10 sum = sum + (digit³) num = num DIV 10 No sum == original? Yes No Print “Armstrong” Print “Not Armstrong” Stop
17. Following is an algorithm to classify numbers as “Single Digit”, “Double Digit” or “Big”.
Classify_Numbers_Algo
INPUT Number
IF Number < 9
    "Single Digit"
Else If Number < 99
    "Double Digit"
Else
    "Big"
Verify for (5, 9, 47, 99, 100, 200) and correct the algorithm if required
Given algorithm uses:
STEP 1: INPUT Number
STEP 2: IF Number <= 9 THEN
STEP 3:     PRINT "Single Digit"
STEP 4: ELSE IF Number <= 99 THEN
STEP 5:     PRINT "Double Digit"
STEP 6: ELSE
STEP 7:     PRINT "Big"
STEP 8: END IF
Verification (dry run outputs):
5 → Single Digit
9 → Single Digit ✅ (fixed)
47 → Double Digit
99 → Double Digit ✅ (fixed)
100 → Big
200 → Big
18. For some calculations, we want an algorithm that accepts only positive integers upto 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?
(a) On what values will this algorithm fail?
Given condition is 0 <= Number <= 100, so it will wrongly ACCEPT 0, but 0 is not positive.
Also, if the input is not an integer (like 50.5), the condition still looks “true” unless we explicitly check “integer”.
(b) Improved algorithm
STEP 1: INPUT Number

STEP 2: IF (Number >= 1) AND (Number <= 100) AND (Number is an integer) THEN
STEP 3:     ACCEPT
STEP 4: ELSE
STEP 5:     REJECT
STEP 6: END IF