Introduction to Engineering
and Technology
Presented by
Dr. May
Algorithms and Flowchart
Presented by
Dr. May
Purpose of This Lecture
• This lecture reviews an introduction to Algorithms and flowchart.
Lecture Outline
• Introduction
• Algorithms
• Flowchart
• Summary
Introduction
• A program is a set of instruction gave to the computer to execute
successive operations leads to solve specific problem.
• Algorithms and flowchart are two different ways to solve problems.
• In general to solve any problem in computer we must follow these
steps:
1. Analyze the problem
2. Write an Algorithm
3. Draw flowchart
4. Convert the flowchart to program
5. Run the program and test the solution
Algorithms
• Algorithms consist of steps for solving a particular problem.
• It is a combination of phrases and events that can be arranged as steps
to solve a specific problem.
• That can be done by understanding this problem whether it
mathematic or logic before convert it to flowchart.
Algorithms
• Example: when we borrow some books from the library, the
remaining books number (NR) is the subtraction of the borrowed
books number (NB) from the original number (NO).
• To write the algorithm for this simple problem we will follow these
steps:
Input the number of books in the library (NO).
Input the number of borrowed books (NB).
Find the remaining books number (NR), NR = NO - NB
Print NR
Flowchart
• Flowcharts are graphs that represent the formal view used to solve any
problem.
• Flowcharts help the programmer to write his program.
• Flowcharts consist of a shapes connected by a straight lines.
• Flow chart can be used for representing an algorithm.
Flowchart – symbols
Start - Stop Process
Input - Condition
Output
Start
Flowchart – examples
Read A A = 50
• 1) Find sum of two numbers.
Read B B = 40
Sum = A + B Sum = 50+40
Print sum Sum = 90
End
Start
Flowchart – examples
Read A, B ,C A=5,B=3,c=2
• 2) Get average of 3 numbers
Sum = A + B+C Sum = 10
Average = sum /3 Average = 10/3
Print Average Average = 3.3333
End
Start
Flowchart – examples sum = 0
count = 1
• 3) Sum numbers from 1 to 10
Solution:
0 + 1 = 1 sum = sum + count
1 + 2 = 3
3 + 3 = 6
count = count + 1
6 + 4 = 10
10 + 5 = 15
15 + 6 = 21
21 + 7 = 28 No count YES
Print sum
28 + 8 = 36 > 10
36 + 9 = 45
45 + 10 = 55
End
Start
Flowchart – examples Read A , B, C
• 4) Find Max of 3 numbers
YES No
A>B
Solution:
A, B, C
If (A > B) No No
A>C B>C
YES NO
If (A > C) If (B > C) YES YES
YES YES Print C Print B
Print A
MAX = A MAX = B
NO NO
MAX = C End