P - 01 PseudoCode - Algorithm
P - 01 PseudoCode - Algorithm
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
== != == != Comparison
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