Class | Subject | Book | Chapter | Session | Questions covered |
|---|---|---|---|---|---|
XI | Computer Science | Computer Science (NCERT) | 4 – Introduction to Problem Solving | 2026-27 | 18 of 18 |
Chapter at a glance
Idea | Key point |
|---|---|
Steps of problem solving | Analyse the problem → develop an algorithm → code → test and debug |
Algorithm | Finite sequence of precise, unambiguous steps with input and output |
Flowchart | Diagram of an algorithm: oval (start/stop), rectangle (process), parallelogram (input/output), diamond (decision), arrow (flow) |
Pseudocode | Informal, English-like description of the steps (INPUT, COMPUTE, PRINT, IF…ELSE, WHILE) |
Flow of control | Sequence, selection (conditionals), repetition (iteration/loops) |
Verification | Dry run with test values to check correctness |
Decomposition | Breaking a complex problem into smaller sub-problems |
Exercise Questions
Write pseudocode that reads two numbers and divide one by another and display the quotient.
Answer
Answer
INPUT num1
INPUT num2
IF num2 == 0 THEN
PRINT "Division by zero is not possible"
ELSE
COMPUTE quotient = num1 / num2
PRINT quotient
END IF
Read num1 and num2; if num2 is not zero, compute quotient = num1 / num2 and print it.
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?
Answer
Answer
Step 1: SET p1 = 0, p2 = 0, flip = 0
Step 2: WHILE p1 < 3 AND p2 < 3 AND flip < 5
INPUT winner (1 or 2)
IF winner == 1 THEN p1 = p1 + 1
ELSE IF winner == 2 THEN p2 = p2 + 1
flip = flip + 1
Step 3: IF p1 == 3 THEN PRINT "Player 1 takes the cake"
ELSE PRINT "Player 2 takes the cake"
Step 4: STOP
Since there are 5 flips, one player must reach 3 wins; the loop stops as soon as anyone gets 3.
Count wins for each player in a loop, stopping when either reaches 3; the player with 3 wins takes the cake.
Write the pseudocode to print all multiples of 5 between 10 and 25 (including both 10 and 25).
Answer
Answer
SET num = 10
WHILE num <= 25
PRINT num
num = num + 5
END WHILE
Output: 10 15 20 25
Start at 10 and print, adding 5 each time while num ≤ 25 → 10, 15, 20, 25.
Give an example of a loop that is to be executed a certain number of times.
Answer
Answer
A loop that prints the multiplication table of 7 runs exactly 10 times:
SET i = 1
WHILE i <= 10
PRINT 7 * i
i = i + 1
END WHILE
In Python: for i in range(1, 11): print(7 * i)
Other example: taking attendance of 40 students one by one.
Printing a multiplication table of 7 — the loop runs exactly 10 times (i = 1 to 10).
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.
Answer
Answer
Step 1: SET total = 0
Step 2: WHILE total < 200
INPUT amount (10, 20 or 50)
total = total + amount
Step 3: PRINT "Total collected:", total
Step 4: STOP
The number of contributions is not known in advance, so the loop runs until the condition total < 200 becomes false.
Initialise total = 0; repeatedly input an amount and add it while total < 200; then print total.
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.
Answer
Answer
INPUT price
INPUT quantity
COMPUTE bill = price * quantity
PRINT "Bill:", bill
COMPUTE billGST = bill + 0.05 * bill
PRINT "Bill GST:", billGST
Example: price = 40, quantity = 5 → bill = 200, Bill GST = 210.
bill = price × quantity; Bill GST = bill × 1.05; print both.
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
Answer
Answer
INPUT cs, maths, physics
COMPUTE aggregate = cs + maths + physics
COMPUTE percentage = (aggregate / 300) * 100
PRINT "Aggregate:", aggregate
PRINT "Percentage:", percentage
aggregate = cs + maths + physics; percentage = aggregate / 300 × 100.
Write an algorithm to find the greatest among two different numbers entered by the user.
Answer
Answer
Step 1: INPUT a, b
Step 2: IF a > b THEN
PRINT a, "is greater"
ELSE
PRINT b, "is greater"
Step 3: STOP
Read a and b; if a > b print a, else print b.
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.
Answer
Answer
The question does not say whether the boundary values are included; here 5, 15 and 25 belong to the range that starts with them.
Step 1: INPUT num
Step 2: IF num >= 5 AND num < 15 THEN
PRINT "GREEN"
ELSE IF num >= 15 AND num < 25 THEN
PRINT "BLUE"
ELSE IF num >= 25 AND num < 35 THEN
PRINT "ORANGE"
ELSE
PRINT "ALL COLOURS ARE BEAUTIFUL"
Step 3: STOP
Use IF–ELSE IF on the ranges 5–15 (GREEN), 15–25 (BLUE), 25–35 (ORANGE); otherwise print ALL COLOURS ARE BEAUTIFUL.
Write an algorithm that accepts four numbers as input and find the largest and smallest of them.
Answer
Answer
Step 1: INPUT a, b, c, d
Step 2: SET large = a, small = a
Step 3: FOR each n in (b, c, d)
IF n > large THEN large = n
IF n < small THEN small = n
Step 4: PRINT "Largest:", large, "Smallest:", small
Step 5: STOP
Example: 7, 2, 9, 4 → largest 9, smallest 2.
Assume the first number is both largest and smallest, compare it with each of the other three, updating large and small; print them.
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.
Answer
Answer
Step 1: INPUT units
Step 2: IF units <= 100 THEN
charge = units * 5
ELSE IF units <= 250 THEN
charge = 100 * 5 + (units - 100) * 10
ELSE
charge = 100 * 5 + 150 * 10 + (units - 250) * 20
Step 3: total = charge + 75
Step 4: PRINT "Total water bill:", total
Step 5: STOP
Check: units = 300 → 500 + 1500 + 50 × 20 = 3000; total = 3000 + 75 = ₹ 3075.
Charge slab-wise (5 / 10 / 20 per unit for 0–100 / 101–250 / above 250), add ₹ 75 meter charge; e.g. 300 units → ₹ 3075.
What are conditionals? When they are required in a program?
Answer
Answer
Conditionals are statements that test a condition (an expression that is True or False) and choose which set of statements to execute, e.g. IF, IF–ELSE, IF–ELSE IF (in Python: if, elif, else).
They are required whenever the program must make a decision — when different actions are needed for different situations. Examples:
- Checking whether a number is even or odd.
- Deciding pass/fail from marks.
- Calculating a bill with different slab rates.
- Validating input (e.g. rejecting a negative age).
Conditionals are decision-making statements (IF, IF–ELSE) that execute different steps depending on whether a condition is true or false; they are needed whenever a program must choose between alternatives.
Match the pairs (flowchart symbols with their functions): Flow of Control, Process Step, Start/Stop of the Process, Data, Decision Making.
Answer
Answer
Flowchart symbol | Function |
|---|---|
Arrow (→) | Flow of control |
Rectangle | Process step |
Oval / rounded rectangle (terminal) | Start/Stop of the process |
Parallelogram | Data (input/output) |
Diamond | Decision making |
Arrow – flow of control; rectangle – process step; oval – start/stop; parallelogram – data (input/output); diamond – decision making.
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
Answer
Answer
Improved algorithm with decisions for other options:
Reach_School_Algorithm
a) Wake up
b) Get ready
c) Take lunch box
d) IF school bus is available THEN
Take bus; get off the bus at school
ELSE IF a parent can drop me THEN
Go by car / scooter with parent
ELSE IF school is near THEN
Walk or cycle to school
ELSE
Take public transport (auto / metro / city bus)
e) Reach school or college
Further improvements: check the timetable and pack books before leaving; check the weather and take an umbrella if it is raining; if it is a holiday, do not go.
Add decisions: if the bus is available take it; else go with a parent, walk/cycle if near, or use public transport — plus checks for holiday, weather and packing books.
Write a pseudocode to calculate the factorial of a number (Hint: Factorial of 5, written as 5! = 5 × 4 × 3 × 2 × 1).
Answer
Answer
INPUT num
IF num < 0 THEN
PRINT "Factorial is not defined for negative numbers"
ELSE
SET fact = 1
SET i = 1
WHILE i <= num
fact = fact * i
i = i + 1
END WHILE
PRINT "Factorial:", fact
END IF
Check: num = 5 → 1 × 1 × 2 × 3 × 4 × 5 = 120. (0! = 1 since the loop does not run.)
Set fact = 1 and multiply by i for i = 1 to num; print fact (5! = 120).
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³ + 7³ + 1³ = 371.
Answer
Answer
Logic: extract digits one by one using % 10 (last digit) and // 10 (remove last digit), add the cube of each digit, then compare the sum with the original number.
Dry run, N = 371: digits 1, 7, 3 → 1 + 343 + 27 = 371 = N → Armstrong.
Flowchart above: sum the cubes of the digits (using % 10 and // 10 in a loop); if sum equals N, print “Armstrong”, else “Not Armstrong”.
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.
Answer
Answer
Verification
Number | Output of given algorithm | Correct output |
|---|---|---|
5 | Single Digit | Single Digit ✓ |
9 | Double Digit | Single Digit ✗ |
47 | Double Digit | Double Digit ✓ |
99 | Big | Double Digit ✗ |
100 | Big | Big ✓ |
200 | Big | Big ✓ |
The algorithm fails for 9 and 99 because the comparisons should use < 10 and < 100 (or <= 9 and <= 99).
Corrected algorithm
Classify_Numbers_Algo
INPUT Number
IF Number < 10
"Single Digit"
ELSE IF Number < 100
"Double Digit"
ELSE
"Big"
(Assumes non-negative integers.)
It fails for 9 and 99; correct it by using Number < 10 for Single Digit and Number < 100 for Double Digit.
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?
Answer
Answer
- The algorithm wrongly accepts 0, which is not a positive integer. It also accepts decimal (non-integer) values such as 2.5 or 99.9, because it does not check that the number is a whole number.
- Improved algorithm:
Accept_1to100_Algo
INPUT Number
IF (Number is an integer) AND (1 <= Number) AND (Number <= 100)
ACCEPT
ELSE
REJECT
In Python the integer check can be Number == int(Number) or isinstance(Number, int).
- It fails for 0 and for non-integers like 2.5. b) Accept only if Number is an integer and 1 ≤ Number ≤ 100.
Topic checklist
- ☒ Pseudocode and algorithms (Q1–3, 5–11, 15)
- ☒ Loops and conditionals (Q4, 12)
- ☒ Flowcharts (Q13, 16)
- ☒ Verification and improvement of algorithms (Q14, 17, 18)