Professional Documents
Culture Documents
CS 111 Introduction To Computer Science: by Wessam El-Behaidy & Amr S. Ghoneim
CS 111 Introduction To Computer Science: by Wessam El-Behaidy & Amr S. Ghoneim
INTRODUCTION TO
COMPUTER SCIENCE
Fall 2018
7
ALGORITHMS
In computer programming
A sequence of instructions to solve a problem
is called program, or code.
8
PROGRAMMING TOOLS
2. Flowcharts
8
WHAT IS A PSEUDO-CODE
… a mixture of:
English statements.
Some mathematical notations.
Selected keywords from programming language.
9
Detailed Algorithm
11
WHAT IS A FLOWCHART?
12
WHAT IS A FLOWCHART?
12
FLOWCHARTS SYMBOLS
Terminal symbol
It is used to represent the start, end of the program
logic.
Input /Output
It is used for input or output.
Process Symbol
It is used to represent the calculations, data movements,
13
initialization operations etc,.
FLOWCHARTS SYMBOLS
Decision Symbol
It is used to denote a decision to be made at that point
Flow lines
It is used to connect the symbols
Connectors
It is used to connect the flow lines.
14
FLOWCHARTS
Pseudocode:
15
FLOWCHARTS
Example1 (continued)
Flowchart
Algorithm
START
Step 1: Input Lft
Step 2: Lcm Lft × 30 Input
Step 3: Print Lcm Lft
Lcm Lft × 30
Print
Lcm
END
16
FLOWCHARTS
Pseudocode:
17
FLOWCHARTS
Example 2 (continued)
Flowchart
Algorithm
START
Step 1: Input W,L
Step 2: A L×W Input
Step 3: Print A L ,W
A L×W
Print
A
END
18
FLOWCHARTS
ax 2 bx c 0
19
FLOWCHARTS
Example 3 (CONT.)
Pseudocode:
1. Input the coefficients (a, b, c) of the quadratic
equation.
2. Calculate d.
3. Calculate x1.
4. Calculate x2.
5. Print x1 and x2.
20
FLOWCHARTS
Example 3 (continued)
START
Algorithm:
Step 1: Input a, b, c Input
a, b, c
Step 2: d sqrt ( b × b - 4× a × c)
sqrt( b × b
Step 3: x1 (-b + d) / (2 × a) d – 4 × a × c(
Step 4: x2 (-b - d) / (2 × a) x1 ( -b + d ) / (2 × a)
Print
x1 , x 2
END 21
PART B
24 Selection (Decision) Control Structure
CONTROL STRUCTURES
Control
Structures
25
Control
Structures
SELECTION (DECISION(
Sequence Selection Repetition
For example:
if A = 10 and B = 20 The answer is? Yes
26
EQUALITY & RELATIONAL OPERATORS
The idea of true/false (Yes/No) answer.
27
SELECTION (DECISION)
Example 4: (i f STATEMENT (
Reads a student grade and write “passed” if it is greater
than or equal 60.
Start
Pseudocode
2. If Grade>= 60
3. Print “Passed”
Print Yes Grade
“Passed >=60
”
No
End 28
SELECTION (DECISION)
BIG B
SMALL A
BIG A BIG B
ELSE SMALL B SMALL A
BIG A
SMALL B
Print BIG, SMALL
29
End
SELECTION (DECISION)
Print “PASS”
end if PRINT PRINT
“PASS” “FAIL”
30
END
SELECTION (DECISION)
Example 7: (Mult i pl e Case s )
31
SELECTION (DECISION)
Example 7: (continued) Algorithm:
Step 1: Read Grade
Step 2: if (GRADE >= 90) then
Print “A”
else
if (GRADE >= 80) then
Print “B”
else
if (GRADE >= 70) then
Print “C”
else
if (GRADE >= 60) then
Print “D”
else 32
Print “F”
Example 7: (continued)
START
Read Grade
Yes Grade No
>=90
”Print “A No
Yes Grade
>=80
”Print “B No
Yes Grade
>=70
”Print “C
Yes Grade No
>=60
”Print “D ”Print “F
33
End
THANKS