Lesson-3-PRINCIPLES-OF-PROGRAMMING-LANGUAGES-Copy (1)
Lesson-3-PRINCIPLES-OF-PROGRAMMING-LANGUAGES-Copy (1)
PROGRAMMING
LANGUAGES
PREPARED BY: DYCYN T. ALVARO
ALGORITHM,
PSEUDOCODE,
&
FLOWCHART
Algorithm
A step-by-step procedure to solve a given problem.
It can be defined as a set of well-defined instructions or rules
designed to solve a specific problem.
It can be used to solve a wide variety of problems, including
mathematical problems, logical problems, and computational
problems.
Algorithms are often written in natural language, but they can also
be written in pseudocode or a programming language, providing a
precise and logical sequence of operations.
Algorithm Example
Algorithm to add two numbers entered by the user.
Step 1: Start
Step 2: Declare variables num1, num2 and sum.
Step 3: Read values num1 and num2.
Step 4: Add num1 and num2 and assign the result to sum using the formula (sum = num1 +
num2)
Step 5: Display sum
Step 6: Stop
Pseudocode
A compact and informal high-level description of a program.
It is a non-executable language that uses natural language
mixed with programming constructs.
It is written in the form of annotations and informational text
that is written in plain English only. Just like programming
languages, it doesn't have any syntax, so it cannot be compiled
or interpreted by the compiler.
Pseudocode Example
Pseudocode to add two numbers entered by the user.
Begin
Initialize num1, num2, sum.
Read num1, num2.
Compute sum as sum = num1 + num2
Write sum
End
Flowchart
A type of diagram that represents an algorithm or process.
It is a graphical representation of an algorithm. It uses different shapes
to represent the different steps in the algorithm. The shapes are
connected by arrows to show the flow of data through the algorithm.
Flowcharts are a helpful way to visualize the flow of data through a
program. They can be used to understand complex algorithms and for
debugging programs. It allows programmers and non-programmers
alike to understand the solution's structure and logic briefly.
Flowchart Symbols
Flowchart Symbols
Flowchart Example
Flowchart to add two numbers entered by the user.
Flowchart Example
Flowchart to determine if the number is Positive or Negative Number
Flowchart Example
Flowchart to determine if the number is Positive or Negative Integer
Flowchart Example
Flowchart to determine if the number is Positive or Negative Integer
Flowchart Example
Flowchart to determine if the number is Positive or Negative Integer
Flowchart Guidelines
•Flowchart starts with a Terminal Symbol
•Flowchart can have only one start and one stop symbol
•On-page connectors are referenced using numbers
•Off-page connectors are referenced using alphabets
•General flow of processes is top to bottom or left to right
•Symbols of flowchart must be connected with arrow
•Arrows should not cross each other