0% found this document useful (0 votes)
13 views34 pages

‏لقطة شاشة 2025-01-16 في 12.42.28 م

The document discusses the process of problem-solving in computer programming, emphasizing the importance of algorithms and flowcharts. It outlines the steps involved in creating an algorithm, including problem analysis, pseudocode development, and flowchart creation. Additionally, it highlights the characteristics of algorithms and the various types of flowcharts used to represent solutions graphically.

Uploaded by

iyahyadaas
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)
13 views34 pages

‏لقطة شاشة 2025-01-16 في 12.42.28 م

The document discusses the process of problem-solving in computer programming, emphasizing the importance of algorithms and flowcharts. It outlines the steps involved in creating an algorithm, including problem analysis, pseudocode development, and flowchart creation. Additionally, it highlights the characteristics of algorithms and the various types of flowcharts used to represent solutions graphically.

Uploaded by

iyahyadaas
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/ 34

CHAPTER TWO

Algorithms and Flowcharts

Introduction
A program is a set of instruction gave to the computer to execute
successive operations leads to solve specific problem. 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.
• Introduction to Algorithms
• Definition: An algorithm is a step-by-step procedure or formula for
solving a problem.
• Importance: Algorithms are fundamental to computer science and
are used in various applications, from simple calculations to
complex data processing.
• 2. Characteristics of Algorithms
• Finiteness: An algorithm must terminate after a finite number of
steps.
• Definiteness: Each step of the algorithm must be precisely defined.
• Input: An algorithm has zero or more inputs.
• Output: An algorithm has one or more outputs.
• Effectiveness: The steps of the algorithm must be basic enough to
be carried out, in principle, by a person using only pencil and paper.
Introduction
A program is a set of instruction gave to the computer to execute
successive operations leads to solve specific problem. 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.
1-1: Algorithms

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 flow chart.
ALGORITHMS AND FLOWCHARTS

• A typical programming task can be divided into two


phases:
• Problem solving phase
– produce an ordered sequence of steps that describe
solution of problem
– this sequence of steps is called an algorithm
• Implementation phase
– implement the program in some programming language
Steps in Problem Solving
• First produce a general algorithm (one can use
pseudocode)
• Refine the algorithm successively to get step by step
detailed algorithm that is very close to a computer
language.
• Pseudocode is an artificial and informal language
that helps programmers develop algorithms.
Pseudocode is very similar to everyday English.
Pseudocode & Algorithm
• Example 1: Write an algorithm to determine a
student’s final grade and indicate whether it is
passing or failing. The final grade is calculated
as the average of four marks.
Pseudocode & Algorithm
Pseudocode:
• Input a set of 4 marks
• Calculate their average by summing and dividing by 4
• if average is below 50
Print “FAIL”
else
Print “PASS”
Pseudocode & Algorithm
• Detailed Algorithm
• Step 1: Input M1,M2,M3,M4
Step 2: GRADE  (M1+M2+M3+M4)/4
Step 3: if (GRADE < 50) then
Print “FAIL”
else
Print “PASS”
endif
The Flowchart
A Flowchart
– shows logic of an algorithm
– emphasizes individual steps and their
interconnections
– e.g. control flow from one action to the next
1-2: Flowcharts

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. The following
table shows these shapes and their operations.
• Flowcharts
• Flowcharts is a graph used to depict or show a
step by step solution using symbols which
represent a task.
• The symbols used consist of geometrical shapes
that are connected by flow lines.
• It is an alternative to pseudocoding; whereas a
pseudocode description is verbal, a flowchart is
graphical in nature.
We can summarize the use of algorithms and flowcharts
as follow:

1. To show the mathematical logic used to solve


problems.
2. To show how the data processing is done.
3. Helps the programmer to write his program.
4. Divides the big problem to smaller parts.
5. To avoid the errors that occurred during writing the
program.
6. It is a middle step between problem difficulty and its
conversion to suitable program.
7. Easy to convert it to any programming language.
Pseudocode & Algorithm
• Example 1: Write an algorithm to determine a
student’s final grade and indicate whether it is
passing or failing. The final grade is calculated
as the average of four marks.
Example
START
Step 1: Input M1,M2,M3,M4
Step 2: GRADE  (M1+M2+M3+M4)/4
Input
M1,M2,M3,M4
Step 3: if (GRADE <50) then
Print “FAIL”
else
GRADE(M1+M2+M3+M4)/4 Print “PASS”
endif
N IS Y
GRADE<5
0

PRINT PRINT
“PASS” “FAIL”

STOP
Example 2
• Write an algorithm and draw a flowchart to
convert the length in feet to centimeter.
Pseudocode:
• Input the length in feet (Lft)
• Calculate the length in cm (Lcm) by
multiplying LFT with 30
• Print length in cm (LCM)
Example 2
Algorithm Flowchart

• Step 1: Input Lft START

• Step 2: Lcm  Lft x 30 Input


Lft

• Step 3: Print Lcm


Lcm  Lft x 30

Print
Lcm

STOP
Example 3
Write an algorithm and draw a flowchart that will
read the two sides of a rectangle and calculate its
area.
Pseudocode
• Input the width (W) and Length (L) of a rectangle
• Calculate the area (A) by multiplying L with W
• Print A
Example 3

Algorithm START

• Step 1: Input W,L Input


W, L
• Step 2: A  L x W
• Step 3: Print A ALxW

Print
A

STOP
In general, we can divide flowcharts to a four
shapes (charts):

1. Simple sequence charts


2. Branched charts.
3. Single loop charts.
4. Multi-loop charts.
1-2-1: Simple sequence charts

The events arrangement of this type is as straight sequence from the beginning of
the program to the end (Event-1 to Event-n in figure below). This type of charts does
not have any branches or loops.

You might also like