March 06, 2026 -
No comments
No comments
Module 2. Lesson 2: Algorithm, Pseudocode, and Flowcharting
Read and Learn
Algorithm – A limited number of instructions that outline the steps to be taken in order to solve a particular problem or a set of related problems.
Criteria for an Algorithm
- Input – There is data that needs to be processed.
- Output – There is a result or report produced.
- Definiteness – Instructions must be clear and free from ambiguity.
- Finiteness – The algorithm must end after a definite number of steps.
- Effectiveness – Steps must be simple and practical to perform.
Pseudocode
Pseudocode is an outline of the logic of the program before writing it in an actual programming language. It describes what the program should do using simple and readable instructions.
Flowchart
A flowchart is a graphical representation of an algorithm that uses symbols to illustrate the sequence of steps in solving a problem.
Definitions of Flowchart
- "Use of symbols and phrases to designate the logic of how a problem is solved."
- "A method for defining logical program steps using symbols representing Input, Process, and Output."
- "A two-dimensional representation of an algorithm using standard symbols."
- "A diagram showing the order in which procedures are carried out; it serves as the blueprint of the program."
Basic Symbols Used in Flowcharting
| Symbol | Explanation |
|---|---|
| Flowline | Arrows that show the direction of flow between steps. |
| Terminator | Represents the Start or End of a program. |
| Process | Represents calculations or data processing. |
| Input / Output | Used for receiving input or displaying output. |
| Decision | Represents a condition where a choice must be made (Yes/No). |
| Predefined Process | Represents a module or subroutine. |
Example: Simple Payroll System
A simple payroll system computes the total salary of an employee using different modules.
1. Read Module
Algorithm- Read Hours and PayRate
- Exit
Read Hours, PayRate Exit
2. Calculation Module
Algorithm- Compute Gross Pay
- Exit
GrossPay = Hours * PayRate Exit
3. Print Module
Algorithm- Print Pay
- Exit
Print Pay Exit
Logic Structures
Programs are built using three main logic structures.
1. Sequence
Processes are executed step-by-step in order.
Example: Accept and display a number Algorithm- Read value of N
- Print value of N
- End
Read N Print N End
2. Selection (IF – THEN – ELSE)
This structure allows the program to choose between alternatives.
Example: Employee Bonus| Salary | Bonus |
|---|---|
| Below 2000 | 50% of Salary |
| Above 2000 | 1500 |
Bonus = 0
Read EmployeeName, Salary
If Salary < 2000
Bonus = Salary * 0.50
Else
Bonus = 1500
Print EmployeeName, Bonus
End
3. Repetition (Loop)
This structure repeats a process while a condition remains true.
Example: Count from 1 to 10
Counter = 1
While Counter <= 10
Print Counter
Counter = Counter + 1
End While
Quiz #5
I. Identify the following terms- Algorithm
- Flowchart
- Pseudocode
- Program
II. Give what is asked
5. Criteria for Algorithm
a. _______b. _______
c. _______
d. _______
e. _______
6. Six Steps in Problem Solving
a. _______b. _______
c. _______
d. _______
e. _______
f. _______
Activity 5
- Create a flowchart that accepts three numbers and displays the highest and lowest.
- Draw a flowchart to determine if a voter is qualified (Age ≥ 18).
- Create a flowchart that converts hours to minutes. (1 hour = 60 minutes)
- Draw a flowchart that checks if a user is authorized. Password = pass.
- Create a flowchart that computes the sum of three numbers.
- Construct a flowchart that accepts 10 numbers and displays positive and negative numbers.
- Create a flowchart that swaps the values of two numbers A and B.
References
- Workbook in C Programming – Gatpandan & Rollan
- Kernighan & Ritchie – The C Programming Language
- Schildt – Turbo C/C++ The Complete Reference
- Sellapan – C++ Through Examples
- Uckan – Problem Solving Using C
- www.cprogramming.com
- www.cplusplus.com
- www.tutorialspoint.com
0 comments:
Post a Comment
If possible, leave a positive comment. No hate speech or elicit comments. Thank you.