Algorithms · Control Structures · Flowcharts · Pseudo Code · Pascal · Language Evolution
Every problem can be broken into three parts that describe how raw data becomes a useful result.
Raw materials or data provided to solve a problem. This is what you start with.
Step-by-step operations that convert input into output. Order matters.
The final result obtained after the process. The answer to the problem.
| Solution | Formula | Operations | Best For |
|---|---|---|---|
| 1st | L+W+L+W | 3 additions | Addition only |
| 2nd | L×2 + W×2 | 2 mult + 1 add | Multiplication known |
| 3rd ✓ | (L+W)×2 | 1 add + 1 mult | Most efficient! |
For each item below click to classify it as Input, Process, or Output for: "Finding the average of 5 exam marks." Click an item multiple times to cycle through categories.
An algorithm is a step-by-step procedure for solving a problem. Three control structures direct the flow.
All steps executed one after another in a fixed order. No conditions, no branching, no loops.
A condition is evaluated. Depending on whether it is True or False, a different set of steps executes.
IF condition THEN statement when True ELSE statement when False ENDIF
One or more steps are repeated until a condition is satisfied (or while a condition remains true). The repeating section is called a loop.
Flowcharts use standard symbols to visually represent an algorithm step by step.
Oval — marks Start or End of algorithm.
Skewed — represents Input or Output.
Square corners — represents a Process.
Diamond — represents a Decision (Yes/No).
Directed line — shows Flow Direction.
Circle — used to connect flowchart parts.
Pure top-to-bottom flow — every step runs exactly once in order.
The diamond creates a branch. One path runs depending on the condition result.
The backward arrow is the key indicator — it creates the loop.
Pseudo code expresses an algorithm in simple English-like terms, independent of any programming language.
BEGIN / ENDMark start and end
INPUT / READ / GETReceive data from user
OUTPUT / DISPLAYShow result to user
CALCULATE / PROCESSPerform computation
IF…THEN…ELSE…ENDIFSelection structure
FOR … DOCount-controlled loop
WHILE … ENDWHILECondition-first loop
REPEAT … UNTILCondition-last loop
BEGIN INPUT Radius CALCULATE Area = 22/7 × Radius × Radius DISPLAY Area END
BEGIN READ number as N CALCULATE Rem = N MOD 2 IF Rem = 0 THEN DISPLAY "Even number" ELSE DISPLAY "Odd number" ENDIF END
BEGIN Total = 0 ; n = 1 WHILE n <= 10 READ Number Total = Total + Number n = n + 1 ENDWHILE DISPLAY Total END
Total = Total + Number is NOT a math equation — it adds Number to current Total and stores backBEGIN Total = 0 ; count = 0 REPEAT READ Number Total = Total + Number count = count + 1 UNTIL count = 10 Average = Total / 10 DISPLAY Total, Average END
BEGIN INPUT N Min = N ; Count = 1 WHILE Count < 10 INPUT N IF N < Min THEN Min = N ENDIF Count = Count + 1 ENDWHILE DISPLAY Min END
Pascal is a high-level, structured programming language ideal for learning fundamental programming concepts.
:= for assignment and = for comparison — mixing them is a common mistake!Art = ART = artSum, Total_Nos, Num1, FirstName, avg, mark_1$75 — starts with $Average Marks — has a space9A — starts with digitLast-name — hyphen not allowedbegin — reserved word0, 46, -12, 999 Declaration: var count : integer;| Op | Usage | Example | Result |
|---|---|---|---|
+ | Addition | 6 + 3 | 9 |
- | Subtraction | 7 - 5 | 2 |
* | Multiplication | 2 * 5 | 10 |
/ | Division (real) | 10 / 4 | 2.50 |
DIV | Integer division | 20 DIV 6 | 3 |
MOD | Remainder | 20 MOD 6 | 2 |
| Operator | Meaning | Example | Result |
|---|---|---|---|
> | Greater than | 7 > 3 | True |
>= | Greater than or equal | 8 >= 8 | True |
< | Less than | 3 < 2 | False |
<= | Less than or equal | 4 <= 6 | True |
= | Equal to | 3 = 1 | False |
<> | Not equal to | 2 <> 5 | True |
AND — BOTH must be True
| A | B | A AND B |
|---|---|---|
| F | F | False |
| F | T | False |
| T | F | False |
| T | T | True |
OR — at least ONE True
| A | B | A OR B |
|---|---|---|
| F | F | False |
| F | T | True |
| T | F | True |
| T | T | True |
| Priority | Operators |
|---|---|
| 1 (highest) | NOT |
| 2 | * / DIV MOD AND |
| 3 | + - OR |
| 4 (lowest) | = <> < <= > >= |
5 + 14 MOD 4 → 14 MOD 4=2 → 5+2 = 7NOT(8 MOD 2 > 5) → 0>5=F → NOT(F) = True(3>=2) AND (3<>3) → T AND F = Falseprogram addNum(input,output); { Program name } var num1, num2, total : integer; { Declare variables } avg : real; begin { Main program starts } Writeln('Enter First Number'); Read(num1); { Input } Writeln('Enter Second Number'); Read(num2); total := num1 + num2; { Process } avg := total / 2; Writeln('Total = ', total); { Output } Writeln('Average = ', avg); end. { Main program ends }
Pascal provides IF-THEN, IF-THEN-ELSE, Nested IF, and CASE statements for selection.
if N > 0 then Writeln('Positive Number');
Read(N1, N2); if N1 > N2 then Large := N1 else Large := N2; Writeln('Large = ', Large);
elsebegin...end; after the THEN statement before else causes a syntax error!Read(M); if M >= 75 then Grade := 'A' else if M >= 65 then Grade := 'B' else if M >= 50 then Grade := 'C' else if M >= 35 then Grade := 'S' else Grade := 'F';
else catches all remaining casesRead(Marks); case Marks of 0..34 : Grade := 'W'; 35..49 : Grade := 'S'; 50..64 : Grade := 'C'; 65..74 : Grade := 'B'; 75..100 : Grade := 'A'; else Writeln('Invalid'); end;
.. notationelse handles unmatched valuesend; (semicolon) — unlike the main program's end. (full stop).Three loop structures handle different repetition scenarios in Pascal programs.
var i, total : integer; begin total := 0; for i := 1 to 10 do begin Writeln(i); total := total + i; end; Writeln('Total = ', total); end.
| Structure | Runs |
|---|---|
for x := 1 to 5 do | 5 times |
for x := 0 to 4 do | 5 times |
for x := 5 to 10 do | 6 times |
begin...end.for count := 10 downto 1 do Writeln(count);
DOWNTO decrements the counter each iteration| Structure | Runs |
|---|---|
for x := 10 downto 5 do | 6 times |
for x := 4 downto 0 do | 5 times |
n := 5; while n <= 50 do begin Writeln(n); n := n + 5; end;
count := 0; repeat Writeln('Pascal'); count := count + 1; until count > 5;
| count | Prints | After | count > 5? |
|---|---|---|---|
| 0 | Pascal | 1 | No → continue |
| 1 | Pascal | 2 | No → continue |
| 2 | Pascal | 3 | No → continue |
| 3 | Pascal | 4 | No → continue |
| 4 | Pascal | 5 | No → continue |
| 5 | Pascal | 6 | Yes → STOP |
Tracing: for i := 1 to 5 do sum := sum + i; (initial sum = 0)
Arrays store multiple same-type values. Sub-programs (Procedures & Functions) organize code into reusable blocks.
{ General syntax } var Name : array[first..last] of type; { Example: 10 integers, index 0–9 } var marks : array[0..9] of integer; { Assign values } marks[0] := 45; marks[1] := 75; { Loop through all elements } for i := 0 to 9 do Writeln(marks[i]);
Performs a task. Control returns to the main program after execution — but no value is sent back.
procedure showArea(var r:real); begin Writeln(22/7 * r * r); end; { Call: } showArea(radius);
Computes and returns a result. The return type is declared after the parameter list.
function square(var n:integer):integer; begin square := n * n; end; { Call: } res := square(5); { res=25 }
Programming languages evolved from complex machine code to human-friendly high-level languages.
| Feature | Machine | Assembly | High-Level |
|---|---|---|---|
| Human readable | No | Partly | Yes |
| Execution speed | Fastest | Fast | Slower |
| Translation needed | None | Assembler | Compiler/Interpreter |
| Machine dependent | Yes | Yes | No |
Translates programs written in Assembly Language (symbolic codes like ADD, MOV) into machine language.
MOV AX, 5 instead of binary like 10110000 00000101.| Feature | Compiler | Interpreter |
|---|---|---|
| Error report | All at once | One by one |
| Speed | Faster | Slower |
| Output file | Yes (.exe) | No |
Describes how step-by-step using procedures.
eg C, Pascal, FORTRAN
Describes what you want — system finds how.
eg SQL, Prolog
Models objects with properties and methods.
eg Java, C++, Python
Based on mathematical functions.
eg Lisp, Haskell
States facts and rules; system deduces answers.
eg Prolog
Queries and manages structured data.
eg SQL
12 questions covering all topics. Click an answer to check immediately.
Exam-style questions with detailed answers. Try each one before revealing the solution.
sum:=0; repeat sum:=sum+5; writeln(sum); until sum>=20;▶if N>0 then Writeln('Y'); followed by else causes a syntax error.