Download as pdf or txt
Download as pdf or txt
You are on page 1of 38

Algorithm & Fundamental

of Programing
Part 01
Stage 3

Hekar A. Mohemmed
Algorithm ??

2
Algorithm Definition
It is a recipe for solving problems.

An algorithm is a finite set of steps


defining the solution of a particular
problem.

A finite set of an instruction that


specifies a sequence of operation in
order to solve a specific problem. 3
How algorithm work ?

4
Finding the largest integer among five integers

5
Methods of Specifying Algorithm
Pseudo code : steps of algorithm using natural
language.

Flowchart : a graphical tool with symbols Show


the sequence of steps in an algorithm.

6
Example 1
Write an algorithm that finds the average of
two numbers

Solution:
start
Input: (number one , number two)
process: (number one + number two)/2
output : average
End 7
Example 2
Write an algorithm to change a numeric grade
to a (pass/fail) grade.

Solution:
start
Input: One number
process: if (number >= 40)
print pass
Else
print fail
End if
output : grade states
End 8
Example 3
Write an algorithm for grading System by
following method.

9
Solution
Start
input: One number
process :
1. if (number >= 80)
print A
End if
2. if (number >= 70 and < 80)
print B
End if
3. if (number >= 60 and < 70)
print C
End if
4. if (number >= 50 and < 60)
print D
End if
5. If (number < 50)
print F
End if
Output: grade stats 10
End
Flowchart
a graphical tool with symbols Show the sequence
of steps in an algorithm.

11
12
Flowchart Constructs
1. Sequence
2. Selection
3. Iteration (Repetition)

13
Example-1
Draw a flowchart that will read the two sides of a
rectangle and calculate its area.
START

Input
Start W, L

Input W,L
A LxW
A L x W
Print A
Print
A
End
14

STOP
Example-2
Draw a flowchart that will take marks of four subjects and
calculate the average. Then if average marks are greater
than 50 print PASS otherwise print FAIL.

Start
Input: M1,M2,M3,M4
AVG (M1+M2+M3+M4)/4
if (AVG <50) then
Print FAIL
else
Print PASS
end if 15
End
Solution START

Input
M1,M2,M3,M4

AVG (M1+M2+M3+M4)/4

no yes
IS
AVG<50

Print Print
PASS FAIL

16

STOP
Example-3
Draw a flowchart to convert the length in centimeter to
meter.
START

Input
length in centimeter

Lm Lcm / 100

Print
length in meter

17
STOP
Google flowchart

18
Sample Exercises

Sample 1: Write an algorithm and draw a flowchart that


calculates the sum of two input numbers and display the
result.

Sample 2: Write an algorithm and draw a flowchart that


computes the average of three input quizzes, and then display
the result.

Sample 3: Write an algorithm and draw a flowchart that


converts the input mile into kilometer .
19
What is a Computer?
A computer is an electronic device that manipulates
information, or data.
It has the ability to store, retrieve , and process data.

20
Computer Working

21
Computer Architecture

22
Program
set of instructions that causes a computer to
perform a task.
A sequence of instructions is called a computer
program .

23
Programming
is the act of writing the program to process data.

24
Programmer
a person who writes code for computer programs.
a person who programs a machine, device, or
application .

25
Programming Language
used by Programmers to write instructions
that a computer can understand to do what the
programmer wants.

26
Algorithm VS Program

a program: is an implementation of an
algorithm to be run on a specific computer.

an algorithm: it does not deal with machine


is a method to solve a problem.

27
Why Programming?
Our civilization runs on software: Most engineering
activities involve software

Programming importance are:


To interact with machines and computers
To automate tasks
To create intelligent machines , etc

28
Ships Design Aircraft Phones
Construction Communication Voice quality
Management Control User interfaces
Monitoring Display Billing
Engine Signal processing Mobility
Gadget control
Monitoring

29
Programing Language Level
Machine Language
Assembly Language
High level Language

30
Machine Language
Written in the form of 0 & 1
The fundamental language of the computer s processor,
also called Low Level Language.
All programs are converted into machine language before
they can be executed.

31
Assembly Language
A low level language that is similar to machine
language.
Uses symbolic operation code to represent the
machine operation code.

32
High level Language
Computer (programming) languages that are
easier to learn.
Uses English like statements.

33
Program Execution Process

34
Compiler
Usually used to translate a high level language into
a machine language.
During translation, the compiler checks for syntax
errors, if any error it gives a error message

35
Interpreter
It translates a statements in a program and
executes that statement immediately.
When an error occurs the execution of the
program is halted and error message is displayed.

36
Compiler Vs. Interpreter

37
Program design phases

Problem Program
Algorithm

Program Design Process has 2 phases:


Problem Solving Phase
Creates an algorithm that solves the problem
Implementation (Coding) Phase
38
Translates the algorithm into a programming language

You might also like