0% found this document useful (0 votes)
16 views31 pages

Chapter 8

Uploaded by

ginukiggt
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views31 pages

Chapter 8

Uploaded by

ginukiggt
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 31

Algorithm

Flowchart and Pseudocode


Algorithm
Flowchart and Pseudocode
Algorithm
An algorithm is a step-by-step procedure to solve a
given problem. The algorithm can be designed through
the use of flowcharts or pseudocode.

Flowchart Pseudocode
To help programmers plan and write Pseudocode is a way of describing
programs, certain programming tools what happens is a computer
were developed. One such tool is program .It is a list of instruction that
Flow chart. show how the program will work.
A flowchart is a graphical It is the combination of human
representation of programming language and programming
instructions. language.
Symbols
•What is a Flow Chart?
• To help programmers plan and write
programs, certain programming tools were
developed. One such tool is Flow chart.
• A flowchart is a graphical representation of
programming instructions.
Anatomy of Flowchart
• A Flow Chart consists of 2 elements:
• Symbols
• Lines
• Symbols are known as Flowchart Symbols.
• Lines are known as Flowlines.
Anatomy of Flowchart
START
Flowchart Symbols:
• Flow chart symbol shows GET READY
the operation that is carried Flowchart
out in a flowchart. Symbol

GO TO SCHOOL

END
Anatomy of Flowchart
FLOWLINES: START
• We read a flowchart by following the
Flowlines. GET READY
• A flowline represents a connecting
Flowlines
path between flowchart symbols.
GO TO SCHOOL

END
FLOWCHART SYMBOLS
• The most commonly used flowchart
symbols are:
START
INPUT
OUTPUT
PROCESS
DECISION
END
Flowchart Symbol Discussion
START
• The start symbol is oval-
shaped with START written in
the middle. START
• The start symbol shows
where a flowchart begins.
Flowchart Symbol Discussion
PROCESS
• The rectangle used in
flowcharts is the process
symbol.
• It indicates a processing
PROCESS
operation such as a
Calculation or an action in
the flowchart.
Flowchart Symbol Discussion
INPUT
The input symbol is used to
mark the point at which we INPUT
put in data .

OUTPUT
The output symbol is used to
mark the point at which we OUTPUT
get the result.
Flowchart Symbol Discussion
DECISION
There may be a point in our
flowchart where the
flowlines branch out.
At this point we have to YES
DECISION
NO
decide which way to go. ?
In a flowchart ,we use a
diamond-shaped symbol
called Decision symbol.
Flowchart Symbol Discussion
DECISION (Cont.)
• The Decision Symbol is used to indicate a choice or a
branch in a routine.
• There will be a question in the symbol.
• The answer to this question will determine the path to
follow.
• This is the only symbol which has more than one path.
Flowchart Symbol Discussion
END
The end symbol is oval-
shaped with END written in
the middle.
END
The end symbol shows
where a routine ends.
Flowchart Symbol Discussion
Connector:
• Sometimes we can’t write a flowchart
in a same page or column at that time
Connector symbol is used to connect
one portion of a flowchart to another.
Flowchart Symbols
Going to school
START

WAKE UP

GET READY

GO TO
SCHOOL

END
Doing homework
START

DO
HOMEWORK

FINISHED?
NO

YES

END
Playing Football
START

GO TO STADIUM

PLAY FOOTBALL

NO TIME TO
GO HOME ?

YES

END
Washing Clothes

START

WASH CLOTHES

ANY MORE
YES CLOTHES ?

NO

END
Doing a Calculation

START

CALCULATE
22X34

WRITE
ANSWER

END
Pseudocode
• Pseudocode is one of the tools that can be used to
write a preliminary plan that can be developed into a
computer program.
• Pseudocode is a generic way of describing an
algorithm without use of any specific programming
language syntax.
• It is the combination of human language and
programming language.
Variable and Assignment statement
• Variable: a Variable is a storage location.
It is a named data location in a program that can be
changed throughout the execution of a program.
• Constant: A constant is also a storage location. It is a
named location that contains value that we don’t
want to change during the running of the program.
We want the value stored there to remain constant.
Rules for naming variables:
1. All variable names must begin with a letter of the alphabet
2. After the first initial letter, variable names may also contain
letters and the digits 0 to 9. except underscore No spaces or
special characters are allowed.
Tip: Some programmers use underscore in variable names to
separate parts of the name, such as shipping_weight.
Others prefer a "capital style" notation, such as
shippingWeight to separate parts of the name. The name can
be of any length, but don't get carried away. Remember that you
will have to type this name.
3. Uppercase characters are distinct from lowercase characters.
4. Remember that variable names are case-sensitive.
5. You cannot use any keyword ( print,input) for a variable name.
Data Types Description
a whole number, • Integer written as normal in the denary system,
INTEGER e.g. 5, –3

a number capable of containing a fractional part. Real always


REAL written with at least one digit on either side of the decimal point,
zeros being added, if necessary, e.g., 4.7, 0.3, –4.0, 0.0

a single character. Char a single character delimited by single


CHAR quotes, e.g. ꞌxꞌ, ꞌcꞌ, ꞌ@ꞌ

String delimited by double quotes. A string may contain no


STRING characters (i.e. the empty string),
e.g. "This is a string", ""

the logical values TRUE and FALSE


BOOLEAN
Variable declarations:

Declarations are made as follows:

DECLARE <identifier>: <data type>

Example – Variable declarations

DECLARE std_name : STRING


DECLARE Counter : INTEGER
DECLARE TotalToPay : REAL
DECLARE GameOver : BOOLEAN
Variable names
Variable names Valid Invalid
1 Std Name
2 Price$
3 Num 1
4 stdID
5 Father-name
6 Emp_ID
7 A+B
8 3D
9 Q-4
10 A3_4_5
11 input
12 Phno#
• Assignment statement : An assignment operation is an instruction in
a program that places a value in a specified variable.
• Example:
Input num [num is a variable]
num 50 [assignment statement]
Sequence in flowchart
2.Draw a flowchart to input 2 numbers given by the user and find the
sum of three numbers.
Sequence in flowchart
3. Draw a flowchart to find the average of three numbers given by the
user.
Pseudocode on Sequence
• Write a pseudocode to find the average of three
numbers given by the user.

DECLARE a,b,c.sum : INTEGER


DECLARE avg : real

Input a,b,c
sum ← a+b+c
avg ← sum/3
Print avg

You might also like