Introduction of Algorithms
and Flowchart
What is an algorithm?
Named after Persian mathematician Mohammad
Al- Khwarizmi
A sequential solution of any problem
Written in human understandable form
Requires a clear understanding of the problem
What is an algorithm?
An algorithm describes
the step by step action to
solve a problem..
What is an algorithm?
An algorithm is a self-contained step-by-
step set of operations to be performed to
solve a specific problem or a class of
problems.
A computer program is a sequence of
instructions that comply the rules of a
specific programming language , written
to perform a specified task with a
computer.
Example of an algorithm
1. For example, an algorithm for driving
to a friend's house could be:
Example of an algorithm
Solution # 1
1. Find your keys
2. Walk out of the house
3. Close the door
4. Open the car door
5. Get into the car
6. Put the key into the ignition
7. Start the car
Example of an algorithm
2. Write an algorithm15
to change a numeric
grade to a pass/fail grade.
Example of an algorithm
Solution # 2
Pass/Fail Grade
Input: One number
if (the number is greater than or equal to 50)
then
1.1 Set the grade to “pass”
else
1.2 Set the grade to “fail”
End if
Print the grade
End
Example of an algorithm
3. Write an algorithm for grading system by following
method.
Marks range Grade
15
>=80 A
>=70 & <80 B
>=60 & <70 C
>=50 & <60 D
<50 F
Example of an algorithm
Solution # 3
Input: One number
1. if (the number is between 80 and 100, inclusive)
then
1. Set the grade to “A”
End if
2. if (the number is between 70 and 79,
inclusive)
then
1. Set the grade to “B”
End if
3. if (the number is between 60 and 69, inclusive)
then
1. Set the grade to “C” End
End if
4. if (the number is between 50 and 59, inclusive)
then
1. Set the grade to “D” End
End if
5. If (the number is less than 50)
then
1. Set the grade to “F” End
End if
6. Print the grade
End
Flowchart
A graphical representation of an
algorithm, often used in the design
phase of programming to work out the
logical flow of a program.
Visual way to represent the information flow
Make our logic more clear
Help during writing of program
Make testing and debugging easy
Basic Flowcharting Symbols
Basic Flowcharting Symbols
SYMBOL ACTIVITY
ON PAGE CONNECTOR
OFF PAGE
CONNECTOR
Flowchart or program constructs
Sequence: The order of execution, this
typically refers to the order in which the
code will execute. Normally code
executes line by line, so line 1 then 2
then 3 and so on.
Selection: Selection, like branching, is a
method of controlling the execution
sequence, you can create large control
blocks, using if statements testing a
Flowchart or program constructs
condition, or switch statements
evaluating a variable etc to control and
change the execution of the program
depending on this environment and
changing variables.
Iteration (Repetition): Iteration is typically
used to refer to collections and arrays of
variables and data. Repeating set of
instruction. Counting from 1 to 10, you are
Flowchart or program constructs
iteratingover the first 10 numbers. for,
while, do-while loops will be
implemented for iteration.
Flowchart or program constructs
Flowchart or program constructs
Flowchart or program constructs
Write an algorithm and draw a flowchart that will read
the two sides of a rectangle and calculate its area.
Algorithm
Step 1: Start
Step 2: Take Width and Length as input
Step 3: Calculate Area by Width* Length
Step 4: Print Area.
Step 5: End
START
Step 1: Start
Input
Step 2: Input W, L W, L
Step 3: A = L x W
Step 4: Print A A = Lx W
Step 5: End
Print
A
END
Write an algorithm and draw a flowchart
that will take marks of four subjects and
calculate the average. Then if average
marks are greater than 50 then print
PASS otherwise print FAIL.
START
Input Step 1: Start
M1,M2,M3,M4 Step 2: Input M1,M2,M3,M4
Step 3: AVG = (M1+M2+M3+M4)/4
AVG(M1+M2+M3+M4)/4
Step 4: if (AVG <50) then
Print “FAIL”
N IS Y
else
AVG<50
Print “PASS”
Print
“PASS”
Print
“FAIL”
endif
Step 5: End
END
Write an algorithm and draw a
flowchart to convert the length in feet
to centimeter.
Flowchart
Algorithm START
Step 1: Start
Input
Step 2: Input ft ft
Step 3: cm = ft * 30
cm = ft x 30
Step 4: Print cm
Step 5: End
Print cm
END
THANK YOU!!!