Definition of an Algorithm:
Main Methods of Designing Algorithms:
Definition:
Functionality:
Example:
Definition:
Components:
Definition:
Advantages:
Example Scenario:
INPUT Age
IF Age >= 18 THEN
OUTPUT "Welcome to the site"
ELSE
OUTPUT "Sorry, this site is for users 18 and over"
ENDIF
INPUT FName
INPUT Age
IF Age >= 18 THEN
OUTPUT "Welcome to the site, " + FName
ELSE
OUTPUT "Sorry, this site is for users 18 and over"
ENDIF
Purpose:
Interpretation Tools:
Complex Algorithms:
Example to Explain:
Count ← 1
Number ← 0
Total ← 0
REPEAT
INPUT Number
Total ← Total + Number
Count ← Count + 1
UNTIL Count > 10
OUTPUT Total
Purpose:
A teacher's algorithm for entering student marks and grading them.
Pseudocode:
Count ← 0
REPEAT
INPUT Score[Count]
IF Score[Count] >= 70 THEN
Grade[Count] ← "A"
ELSE
IF Score[Count] >= 60 THEN
Grade[Count] ← "B"
ELSE
IF Score[Count] >= 50 THEN
Grade[Count] ← "C"
ELSE
IF Score[Count] >= 40 THEN
Grade[Count] ← "D"
ELSE
IF Score[Count] >= 30 THEN
Grade[Count] ← "E"
ELSE
Grade[Count] ← "F"
ENDIF
ENDIF
ENDIF
ENDIF
ENDIF
Count ← Count + 1
UNTIL Count = 30
Explanation of the Algorithm:
Score[]
. Grade[]
at the same index as input marks.