Professional Documents
Culture Documents
2-3 Flowchart Dan Pseudocode
2-3 Flowchart Dan Pseudocode
5
Following Pseudocode
While ( the quotient is not zero )
Divide the decimal number by the new base
Make the remainder the next digit to the left in the answer
Replace the original decimal number with the quotient
What is 93 in base 8?
93/8 gives 11 remainder 5
11/8 gives 1 remainder 3
1/ 8 gives 0 remainder 1
answer 135
6
Pseudocode for Complete
Computer Solution
Write "Enter the new base"
Read newBase
Write "Enter the number to be converted"
Read decimalNumber
Set quotient to 1
While (quotient is not zero)
Set quotient to decimalNumber DIV newBase
Set remainder to decimalNumber REM newBase
Make the remainder the next digit to the left in the answer
Set decimalNumber to quotient
Write "The answer is "
Write answer
7
Pseudocode Functionality
Variables
Names of places to store values
quotient, decimalNumber, newBase
Assignment
Storing the value of an expression into a
variable
Set quotient to 64
quotient <-- 64
8
quotient <-- 6 * 10 + 4
Pseudocode Functionality
Output
Printing a value on an output device
Write, Print
Input
Getting values from the outside word and storing them into
variables
Get, Read
9
Pseudocode Functionality
Repetition
Repeating a series of statements
Set count to 1
While ( count < 10)
Write "Enter an integer number"
Read aNumber
Write "You entered " + aNumber
Set count to count + 1
10
Pseudocode Functionality
Selection
Making a choice to execute or skip a statement (or
group of statements)
Read number
If (number < 0)
Write number + " is less than zero."
or
Write "Enter a positive number."
Read number
If (number < 0)
Write number + " is less than zero."
11
Write "You didn't follow instructions."
Pseudocode Functionality
Selection
Choose to execute one statement (or group of
statements) or another statement (or group of
statements)
If ( age < 12 )
Write "Pay children's rate"
Write "You get a free box of popcorn"
else If ( age < 65 )
Write "Pay regular rate"
else
Write "Pay senior citizens rate"
12
Pseudocode & Algorithm
Pseudocode:
Input a set of 4 komponen
Hitung rata-rata mereka dengan menjumlahkan
dan membaginya dengan 4
if rata2 dibawah 50
Print “GAGAL”
else
Print “LOLOS”
Pseudocode & Algorithm
Detailed Algorithm
Step 1: Input M1,M2,M3,M4
Step 2: GRADE (M1+M2+M3+M4)/4
Step 3: if (GRADE < 50) then
Print “FAIL”
else
Print “PASS”
endif
The Flowchart
A Flowchart
menunjukkan logika algoritma
menekankan langkah-langkah individu dan interkoneksi
secara keseluruhan
Misal : aliran kontrol dari satu tindakan ke depan
Flowchart Symbols
Basic
Name Symbol Use in Flowchart
PRINT PRINT
“PASS” “FAIL”
STOP
Example 2
START
Algorithm
Input
Step 1: Input Lft Lft
STOP
Example 3
Print
A
STOP
Example 4
Tulis algoritma dan gambar flowchart yang akan
menghitung akar persamaan kuadrat
ax 2 bx c 0
Hint: d = sqrt (b 2 4ac),
and the roots are:
x1 = (–b + d)/2a and
x2 = (–b – d)/2a
Example 4
Pseudocode:
Input the coefficients (a, b, c) of the quadratic equation
Calculate d
Calculate x1
Calculate x2
Print x1 and x2
Example 4
START
Algorithm:
Step 1: Input a, b, c Input
a, b, c
Step 2: d sqrt ( b b 4 ) a c
Step 3: x1 (–b + d) / (2 x a) d sqrt(b x b – 4 x a x c)
Step 4: x2 (–b – d) / (2 x a)
x1 (–b + d) / (2 x a)
Step 5: Print x1, x2
X2 (–b – d) / (2 x a)
Print
x1 ,x2
STOP
DECISION STRUCTURES
Y N
is
A>B
Print A Print B
IF–THEN–ELSE STRUCTURE
print B
endif Print A Print B
Relational Operators
Relational Operators
Operator Description
> Greater than
< Less than
= Equal to
Greater than or equal to
Less than or equal to
Not equal to
Example 5
Input
VALUE1,VALUE2
Y is
N
VALUE1>VALUE2
Print
“The largest value is”, MAX
STOP
NESTED IFS