COS 102 · Problem Solving
Our notes
2 min readWhat pseudocode is
Pseudocode describes an algorithm in plain, structured English, close to a program but not tied to any language. It ignores the fussy details of syntax so you can focus on logic, and it converts easily into Python, C or any other language.
Common keywords
| Purpose | Keywords |
|---|---|
| Start and end | BEGIN, END |
| Input and output | READ / INPUT, PRINT / DISPLAY |
| Assignment | SET X TO 5, or X ← 5 |
| Selection | IF ... THEN ... ELSE ... ENDIF; CASE ... ENDCASE |
| Repetition | WHILE ... DO ... ENDWHILE; FOR I ← 1 TO N ... ENDFOR; REPEAT ... UNTIL |
Indent the lines inside each structure so the shape is clear.
Worked example: average of N numbers
BEGIN
READ N
SET SUM TO 0
FOR I ← 1 TO N
READ X
SUM ← SUM + X
ENDFOR
AVERAGE ← SUM / N
PRINT AVERAGE
END
Trace with N = 3 and numbers 60, 75, 84: SUM = 60, 135, 219; AVERAGE = 219 / 3 = 73.
Worked example: grading
BEGIN
READ SCORE
IF SCORE ≥ 70 THEN GRADE ← "A"
ELSE IF SCORE ≥ 60 THEN GRADE ← "B"
ELSE IF SCORE ≥ 50 THEN GRADE ← "C"
ELSE IF SCORE ≥ 45 THEN GRADE ← "D"
ELSE IF SCORE ≥ 40 THEN GRADE ← "E"
ELSE GRADE ← "F"
ENDIF
PRINT GRADE
END
Trace: 65 → B; 45 → D; 39 → F. (This is the usual Nigerian five-point scale; check your faculty's.)
WHILE and REPEAT
- WHILE checks the condition first, so the body may run zero times.
- REPEAT ... UNTIL checks at the end, so the body runs at least once (good for menus and input checks).
Example: keep asking until a valid score (0 to 100) is entered:
REPEAT
READ SCORE
UNTIL SCORE ≥ 0 AND SCORE ≤ 100
Good habits
- One action per line.
- Meaningful names (TOTAL, not T).
- Close every IF and loop clearly.
- Test it by hand (a trace table: one column per variable, one row per step).
Exams usually ask
- Write pseudocode for a problem and trace it with given data.
- Convert a flowchart into pseudocode or the other way round.
Common mistake
Mixing in language-specific details (semicolons, brackets) or leaving out the END of a structure.
Written by the UniHive team in our own words. Spotted a mistake? Tell us on WhatsApp.
Read
-
Pseudocode
(opens en.wikipedia.org in a new tab)
Wikipedia, Pseudocode, CC BY-SA 4.0 · licence
-
Trace table
(opens en.wikipedia.org in a new tab)
Wikipedia, Trace table, CC BY-SA 4.0 · licence
-
NPTEL: Problem Solving through Programming in C (IIT Kharagpur, whole course)
Algorithms, flowcharts and pseudocode, then variables, decisions, loops, arrays and functions in C (the ideas carry over to Fortran and Python). Video lectures, many hours in all: watch on Wi-Fi where you can.
(opens nptel.ac.in in a new tab)
NPTEL, NPTEL: Problem Solving through Programming in C (IIT Kharagpur, whole course), CC BY-NC-SA 4.0 · licence
Watch
-
Best pick What is Pseudocode Explained | How to Write Pseudocode Algorithm | Examples, Benefits & Steps
5 min · ≈ 23 MB · about ₦13
(opens youtube.com in a new tab)
-
How to convert Flow Chart to Psuedocode| Computer Exam Question
4 min · ≈ 18 MB · about ₦10
(opens youtube.com in a new tab)
-
What is pseudocode and how do you use it?
11 min · ≈ 50 MB · about ₦28
(opens youtube.com in a new tab)
-
What Is Pseudocode? The Programmer's Time-Saving Tool
10 min · ≈ 45 MB · about ₦25
(opens youtube.com in a new tab)
-
5 Minutes to Code: Programming Basics "Pseudocode"
5 min · ≈ 23 MB · about ₦13
(opens youtube.com in a new tab)
-
CS50x - Lecture 0 - Scratch
2 h 1 min · ≈ 545 MB · about ₦306
(opens youtube.com in a new tab)
We link to free material and never copy it. Every link was opened by our team before it went up; video data is a rough guide at 360p.