Friday, 6 March 2026

March 06, 2026 - 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
  1. Read Hours and PayRate
  2. Exit
Pseudocode
Read Hours, PayRate
Exit

2. Calculation Module

Algorithm
  1. Compute Gross Pay
  2. Exit
Pseudocode
GrossPay = Hours * PayRate
Exit

3. Print Module

Algorithm
  1. Print Pay
  2. Exit
Pseudocode
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
  1. Read value of N
  2. Print value of N
  3. End
Pseudocode
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
Pseudocode
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
  1. Algorithm
  2. Flowchart
  3. Pseudocode
  4. 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

  1. Create a flowchart that accepts three numbers and displays the highest and lowest.
  2. Draw a flowchart to determine if a voter is qualified (Age ≥ 18).
  3. Create a flowchart that converts hours to minutes. (1 hour = 60 minutes)
  4. Draw a flowchart that checks if a user is authorized. Password = pass.
  5. Create a flowchart that computes the sum of three numbers.
  6. Construct a flowchart that accepts 10 numbers and displays positive and negative numbers.
  7. 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.