 # Developing logic (Examples on algorithm and flowchart)

## Presentation on theme: "Developing logic (Examples on algorithm and flowchart)"— Presentation transcript:

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 Operator Description > Greater than <
Smaller than Smaller than or Equal Greater than or Equal = Equal Not Equal 2

If else structure The structure is as follows If condition then
true alternative else false alternative endif 3

If else structure is A>B Print B Print A Y N Print A Print B 4

Example (1) 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 5

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
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. Name: Flowlinee: Used to connect symbols and indicate the flow of logic Terminal: Used to represent the beginning or the end of task Input/output: Used for input and output operations, such as reading and printing. Processing: Used for arithmetic and data manipulation operations Decision: Used for any logic or comparison operations. Unlike the two other symbols , which have one entry and one exit flowline, the decision symbol has one entry and two exit paths. Chapter 2- Visual Basic Schneider

Chapter 2- Visual Basic Schneider
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

Chapter 2- Visual Basic Schneider
Start Example of Flowchart: Initialize counter and sum to 0 Are there more data? No Yes Get next grade This is a program to insert grades and calculate the average Determine the average grade of a class Increment counter Add grade to sum Average=sum/counter Print the average Chapter 2- Visual Basic Schneider Finish

Cont.. PRINT “PASS” START Input M1,M2,M3,M4 GRADE(M1+M2+M3+M4)/4
“FAIL” STOP Y N Print “Pass” Print “Fail” 10

Example (2) 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 11