Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
23 views

P - 01 PseudoCode - Algorithm

Uploaded by

bnzrvn7czf
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views

P - 01 PseudoCode - Algorithm

Uploaded by

bnzrvn7czf
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 19

P01 Algorithm and Programming

Pseudo Code and Algorithm


Flowchart
Symbol Name Description
Terminal Shows the start or the end of a flowchart

Line Shows a flow such as data, or control

Process Shows a process such as a calculation or


substitution
Data symbol Shows input or output of data

Decision Shows a control function to select one of


multiple processes by judging a given condition
and its result
Loop limit (Start) Shows the beginning of a loop

Loop limit (End) Shows the end of a loop


Sequential Structure

BEGIN
Do Process[1]
Do Process[2]
END
Example (Addition)
• Input x value and y value BEGIN
• Calculate the sum of x and y and INPUT x
put in result INPUT y
• Display result result ← x + y
OUTPUT result
END
Exercise (Temperature conversion)
• Input Fahrenheit value
• Convert it to Centigrade
• Display Centigrade value
BEGIN
INPUT fahrenheit
centigrade ← (fahrenheit - 32) x 5 / 9
OUTPUT centigrade
END
Selection Structure

BEGIN
IF (Condition) THEN
Do Process[1]
ELSE
Do Process[2]
ENDIF
END
Operators
Operators Type

! ! Logical NOT

*/% */% Arithmetic and modulus

+- +- Arithmetic

< > <= >= < > <= >= Comparison

== != == != Comparison

AND && Logical AND

OR || Logical OR

← = Assignment
Logical Operations(Cont'd)
Logical Operations(Cont'd)
Logical Operations(Cont'd)

NOT GATE
Example (Choose larger value)
BEGIN
• Input a value and b value
INPUT x
• Compare the value of a and b INPUT y
and define which one is larger IF ( x > y )
• Display the larger value result ← x
ELSE
result ← y
ENDIF
OUTPUT “Large value” + result
END
Selection Structure2

BEGIN
IF (Condition1) THEN
Do Process[1]
ELSE IF (Condition2) THEN
Do Process[2]
ELSE
Do Process[3]
ENDIF
END
Exercise (Choose largest value)
• Input a, b and c value
• Compare the value of a, b and c and define which one is largest
• Display the largest value
Repetitive Structure

BEGIN
Do Process[1]
WHILE (Condition1)
Do Process[2]
Do Process[3]
ENDWHILE
END
Repetitive Structure

BEGIN
Do Process[1]
REPEAT
Do Process[2]
Do Process[3]
UNTIL (Condition)
END
Example
• Let's sample value as 5.
• Sum total will do 5 times. To calculate the total value, the user must
input the value.
• Display the result
Exercise (Sum starting 1 to input number)
• Input number of times n
• Sum total as the number of times n
• Display result

• Let's assume n => 5


• The calculation will be 1 + 2 + 3 + 4 + 5 => 15
• The result will be 15
Exercise (Sum of Input values)
• Input sample value
• Sum total till the user input sample value is 11. (that means when
user typing 11, the repetitive process will be stopped)
• Display the result
Exercise (Fibonacci)
• Input number of times n
• Fibonacci sequence will be generated

• Let's assume n => 8


• Program will be displayed as following
1 1 2 3 5 8 13 21

You might also like