CS-101 Lecture 10 Algorithm and Flow Chart Developing logic (Examples on algorithm and flowchart)...
-
Upload
colin-richards -
Category
Documents
-
view
213 -
download
0
Transcript of CS-101 Lecture 10 Algorithm and Flow Chart Developing logic (Examples on algorithm and flowchart)...
CS-101
Lecture 10
Algorithm and Flow Chart Developing logic (Examples on
algorithm and flowchart) Department of Computer Science
College of Arts and Science
1
Relational Operator
2
Operator Description
> Greater than
< Smaller than
≤ Smaller than or Equal
≥ Greater than or Equal
= Equal
≠ Not Equal
If else structure
3
• The structure is as followsIf condition then
true alternative else
false alternativeendif
If else structure
4
isA>B
Print BPrint A
Y N
Print A Print B
Example (1)
5
Step 1: Start.
Step 2: Input M1,M2,M3,M4
Step 3: GRADE (M1+M2+M3+M4)/4
Step 4: if (GRADE < 60) then
Print “FAIL”
else
Print “PASS”
endif
Example (2)
Write a algorithm to find out number is odd or even?• step 1 : start• step 2 : input number• step 3 : rem=number mod 2• step 4 : if rem=0 then• print "number even"• else• print "number odd"• endif• step 5 : stop
Mr.Mohammed Rahmath
Chapter 2- Visual Basic Schneider 7
What is a flowchart?
• Diagram that visually represents the steps that the program performs to arrive at a solution.
• A popular logic tool used for showing an algorithm in graphical form.
Chapter 2- Visual Basic Schneider 8
Continue flowchart• Programmer draws flowchart before coding.• Most common flowchart symbols are:
– Flowline: indicates flow of logic. (arrow )
– Terminal: represents beginning or end of task (oval )
– Input/Output: represents input or output operations (parallelogram )
– Processing: data manipulation operations (rectangle )
– Decision: used for logic or comparison operation (diamond )
Chapter 2- Visual Basic Schneider 9
Example of Flowchart:Start
Initialize counterand sum to 0
Are there more data?
Get next grade
Increment counter
Add grade to sum
Yes
No
Average=sum/counter
Finish
This is a program to insert grades and calculate the average
Print the average
Cont..
10
PRINT“PASS”
START
InputM1,M2,M3,M4
GRADE(M1+M2+M3+M4)/4
GRADE<60
PRINT“FAIL”
STOP
YN
Print “Fail”Print “Pass”
Example (2)
11
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
Thank you for your attention
12
Lecturer : Aasd Abd Elrashid