Programming 3
Programming 3
MaE1042
Lesson-3
PSEUDOCODES AND FLOWCHARTS
Learning Outcomes
Create simple algorithms for solving simple problems using
pseudocode and flowcharts.
Algorithm
An algorithm is a sequence of steps to solve a
particular problem or algorithm is an ordered set of
unambiguous steps that produces a result and
terminates in a finite time
Characteristics
Input: An algorithm may or may not require input
Output: Each algorithm is expected to produce at least one
result
Definiteness: Each instruction must be clear and
unambiguous.
Finiteness: If the instructions of an algorithm are executed,
the algorithm should terminate after finite number of steps
Advantages of algorithm
It is a step-wise representation of a solution to a given problem,
which makes it easy to understand.
An algorithm uses a definite procedure.
It is not dependent on any programming language, so it is easy to
understand for anyone even without programming knowledge.
Every step in an algorithm has its own logical sequence so it is easy
to debug.
How to write Algorithms
1 Define your algorithms input:
2 Define the variables:
3 Outline the algorithm's operations:
4 Output the results of your algorithm's operations:
Flowcharts
The first design of flowchart goes back to 1945 which was designed
by John Von Neumann. Unlike an algorithm, Flowchart uses different
symbols to design a solution to a problem. It is another commonly
used programming tool. By looking at a Flowchartone can
understand the operations and sequence of operations performed in
a system. Flowchart is often considered as a blueprint of a design
used for solving a specific problem.
Advantages of flowchart:
Flowchart is an excellent way of communicating the logic of a
program.
Easy and efficient to analyze problem using flowchart.
During program development cycle, the flowchart plays the role of a
blueprint, which makes program development process easier.
After successful development of a program, it needs continuous
timely maintenance during the course of its operation. The flowchart
makes program or system maintenance easier.
It is easy to convert the flowchart into any programming language
code.
Assignment Symbol or =
Eg: to assign value 10 to the variable LENGTH, statement is
LENGTH 10
Or
LENGTH = 10
Assignment Symbol or = …
A=B+C
Add the value stored in variable B and variable C then assign/store
the value in variable C
X = X+1
Add 1 to the value stored in variable X and then assign/ Store the
new value in variable X.
Mathematical Operators
Relational Operators
Logical Operators
Selection control Statements
Loop control Statements
GO TO
unconditional transfer of control statement is used to transfer
control of execution to another step/statement. .
E.g.: The statement GOTO n will transfer control to step/statement n.
INPUT or READ or GET
Accept input(s) /value(s)
PRINT or WRITE or DISPLAY
Output the result(s)
Exercises:
1. Write Algorithm/Pseudocode to find
the sum of two numbers
2. Draw flowchart to find the sum of
two numbers
3. Write Pseudocode and draw Flowchart to convert
temperature from Celsius to Fahrenheit.