Eng:Mona Ahmed Ali Abdullah   1
FLOWCHART
LAB(1)
                              Eng:Mona Ahmed Ali Abdullah   2
Introduction
• This section establishes the foundation for starting the
 solution of simple problems by using a computer.
 An algorithm could be defining as “a step-by-
   step procedure for solving a given task”
                               Eng:Mona Ahmed Ali Abdullah   3
Introduction
• Notation of Algorithm:
 An algorithm must satisfy the following criteria:
  • Input: there is certain number (0 or more) of quantity which
    are externally supplied.
  • Output: at least one quantity is produced.
  • Finiteness: for all cases the algorithm should terminate after
    a finite number of steps.
  • Definiteness: each instruction must be clear and
    unambiguous to avoid any misinterpretation.
    Ex: an operation such as “subtract 2 or 7 from 9” is not
    permitted due to the ambiguity caused by it.
  • Effectiveness: every instruction must be sufficiently basic,
    that it can in principle be carried out by any person.
                       Eng:Mona Ahmed Ali Abdullah   4
Steps of Solving A problem
Solving a problem using a computer passes by
certain steps. These are known as steps or phases
of software development. These steps could be
given as follows:
Phase 1: problem definition.
Phase 2: problem analysis.
Phase 3: algorithm development.
Phase 4: program writing (program coding).
Phase 5: program transfer to the computer.
Phase 6: program testing and translation.
Phase 7: execution of program and output result.
                               Eng:Mona Ahmed Ali Abdullah   5
Algorithms and Programs
• An algorithm can be described in two ways: flowchart, and/or
 pseudo-code.
  1.Flowchart: represents a good, visible graph-wise way of
      solving algorithms.
   2.pseudo-code: a step-by-step procedure written using a
      natural language in way that is very closed to programming
      languages.
• It is also to be mentioned, that the computer program and the
  algorithm are two different representations for the same thing.
  The computer program is often defined to be “the expression of
  an algorithm in a programming language.”
                              Eng:Mona Ahmed Ali Abdullah   6
Program Flowchart
Definition
Block diagram that uses predefined symbols and
interconnecting line to represent the logic and sequence of
specific program operation.
                        Eng:Mona Ahmed Ali Abdullah            7
Basic program flowcharting symbols
        Terminal                                      Processing
        (start/end)                                   (calculation and
                                                      storing
                                                      operation)
         Input/output                                 Decision
         operation                                    (conditional
                                                      branching)
                    Eng:Mona Ahmed Ali Abdullah          8
Basic program flowcharting symbols
                                                  Flow line
            Subprogram
                                                  (direction)
            call
                                                  connection
              comment
                            Eng:Mona Ahmed Ali Abdullah   9
Types of Program Flowcharts
There are three types of program flowcharts:
  Sequential flowchart
  Branching (jump) flowchart.
  Loop (repetition) flowchart.
                                Eng:Mona Ahmed Ali Abdullah   10
Types of Program Flowcharts
• What are Variables?
    The variable is a container for a value that may vary
    during the execution of the program.
•   Variables and data types:
    The data used in algorithms can be of different types. The
    simplest types of data that an
    algorithm might use are:
    -numeric data, e.g., 12, 11.45, 901, etc.
    -alphabetic or character data such as ‘A’, ‘Z’, or ‘This is
    alphabetic’
    -logical data, that is, propositions with true/false values
                                Eng:Mona Ahmed Ali Abdullah   11
Types of Program Flowcharts
•   Naming of variables
    One should always try to choose meaningful names for
    variables in algorithms to improve the readability of the
    algorithm or program. This is particularly important in
    large and complex programs.
                                Eng:Mona Ahmed Ali Abdullah   12
The Sequential Flowchart:
• It is the simplest type of flowcharts, involving no decision
 (i.e. no branches or loops).
• Fig 1 gives an example for this type of flowchart. When
 such a program is executed, each statement will be
 carried out respecting the order given by the flowchart.
 The pseudo-code will be as follows
                         Eng:Mona Ahmed Ali Abdullah        13
The Sequential Flowchart:
•   Start
    Get the sum
    Average = sum / 6
    Output the average
    Stop(end)
                            Fig 1: a sequential flowchart
                                  Eng:Mona Ahmed Ali Abdullah   14
The Sequential Flowchart:
•   Example 1:
    Give a flowchart for finding the square value of a given number.
    Solution:
    At the beginning a value is entered to the numerical variable x.
    The second step involves the
    calculation of the square value of x, and assigning to another
    variable y. the last step is to print
    the values of x and y.
    Steps:
    Step 1: start(begin).
    Step 2: input (enter or read) value of x.
    Step 3: set y = x*x.
    Step 4: output (print) values of x and y.
    Step 5: end.
                Eng:Mona Ahmed Ali Abdullah   15
The Sequential Flowchart:
                     ,y
                                 Eng:Mona Ahmed Ali Abdullah   16
The Sequential Flowchart:
•   Example 2:
    Give a flowchart for finding the summation of three
    numbers.
    Solution:
    Steps:
    Step 1: start.
    Step 2: input (enter) values of x , y and z.
    Step 3: set s = x + y + z .
    Step 4: output (print) value of s.
    Step 5: end.
                Eng:Mona Ahmed Ali Abdullah   17
The Sequential Flowchart:
                   x,y,z
                                 Eng:Mona Ahmed Ali Abdullah   18
The Sequential Flowchart:
•   Example 3:
    Give a flowchart for finding the solution of the following
    equation y = 2x2 + 3z .
    Solution:
    Steps:
    Step 1: start.
    Step 2: input (enter or read) values of x and z.
    Step 3: set y = 2*x*x + 3 * z .
    Step 4: output (print) value of y.
    Step 5: end.
                Eng:Mona Ahmed Ali Abdullah   19
The Sequential Flowchart: