Skip to content
Worked Examples · Example 4.8

Q.Write pseudocode and draw a flowchart to accept 5 numbers and find their average.

Uttarakhand UbseTextbookSubjective· 3mImportance★★★★★est
36% · 13/36 Questions
🔒 Locked · start free trial →

You're viewing a preview — the full solution, concept, methods & PYQ mapping are locked.

Start your 14-day free trial to unlock the full solution →

Since the count of inputs is known in advance (5), use a counter-controlled loop: add each entered number into a running sum, then divide by 5.

The idea. This example introduces repetition (iteration) with a known trip count. Two variables do all the work: count controls how many times the loop body runs, and sum accumulates the inputs. Initialising both to 0 before the loop is essential — the accumulator pattern fails if sum starts undefined.

Pseudocode:

Step 1: SET count = 0, sum = 0
Step 2: WHILE count < 5, REPEAT Steps 3-5
Step 3:     INPUT num
Step 4:     sum = sum + num
Step 5:     count = count + 1
Step 6: average = sum / 5
Step 7: PRINT average

Flowchart (nodes and arrows):

  1. Start (oval)
  2. ↓ count = 0, sum = 0 (rectangle)
  3. ↓ Decision (diamond): "count < 5?"
    • Yes → Input num (parallelogram) → sum = sum + num (rectangle) → count = count + 1 (rectangle) → arrow back up to the decision
    • No → step 4
  4. ↓ average = sum / 5 (rectangle)
  5. ↓ Output average (parallelogram)
  6. ↓ Stop (oval)

Python implementation:

total = 0
for count in range(5):
    num = int(input("Enter number: "))
    total = total + num
average = total / 5
print("Average =", average)

Trace for inputs 4, 7, 3, 16, 20:

Passnumtotal after adding
144
2711
3314

Unlock everything free for 14 days

  • Full step-by-step solutions
  • Concept-first explanations
  • Methods, shortcuts & mistakes
  • PYQ mapping + timed mock tests

Full access for 14 days. No credit card required.