Professional Documents
Culture Documents
Chapter 2 - Problem Solving
Chapter 2 - Problem Solving
Famous muslim
scientist/
mathematician
Sequence set of
steps taken to
solve a problem
(input/process/output)
Must produce
Efficiency
output
Algorithm
Requirements
Finiteness Unambiguous
Correctness Generality
START
print means
IF student's grade is greater than or equal to 60
PRINT the statement "passed" display on the
ELSE screen
PRINT the statement "failed" monitor
ENDIF
END
START show also
IF credit card number is valid means
execute transaction based on number and order display on the
ELSE screen monitor
SHOW a generic failure message
ENDIF
END
Prepared by Norhamreeza Abdul Hamid
set means
START assign the
SET total to zero
value,e.g:
SET grade counter to one
WHILE grade counter is less than or equal to ten total = 0
INPUT the next grade
ADD the grade into the total
ENDWHILE while is used
SET the class average to the total divided by ten whenever the
PRINT the class average.
process is to
END
be continued
Write a program!
START
READ the student mark
IF mark is greater than 85 and mark is less than 100, then
set grade as A
ENDIF
DISPLAY/PRINT the grade Keyword
END
START
INPUT/READ salary per day
CALCULATE the salary= salary*30 days
PRINT/DISPLAY salary
END
Prepared by Norhamreeza Abdul Hamid
START
READ/INPUT pure volume, total rock
CALCULATE porosity = (pure volume / total rock
volume) x 100%
DISPLAY porosity
END
START
READ the value of x
READ the value of a
compute the value of y as y = 2x + a -6
DISPLAY/PRINT the result (or the value of y)
END
Prepared by Norhamreeza Abdul Hamid
Start
Read x
Read a
y = 2x + a - 6
Print y
End
End
Prepared by Norhamreeza Abdul Hamid
A box has height, width and length.
Write the pseudo code to calculate the volume
of a box.
Convert
to
flowchart
Write the pseudo code to calculate salary of
an employee for a month.
Display volume
End
Prepared by Norhamreeza Abdul Hamid
Start
Display salary
End
Prepared by Norhamreeza Abdul Hamid
Start
Display porosity
End
Prepared by Norhamreeza Abdul Hamid
Prepared by Norhamreeza Abdul Hamid
• Sequential
• Selection
• Repetition
END end
Prepared by Norhamreeza Abdul Hamid
Problem: calculate a person’s age
START start
DISPLAY age
END Age = current year –
birth year
Display age
end
START
READ age print “Pencen” print “Kerja lagi”
IF age > 55
PRINT “Pencen”
ELSE
End
PRINT “Kerja lagi”
ENDIF
END
WHILE (condition)
loop-body Condition?
yes Loop
Statement(s)
ENDWHILE
no
initialization
cnt=0
FALSE
condition FALSE
cnt<5 End
TRUE
TRUE
body of loop
Print “whatever”
increment
cnt=cnt+1
START
users = 1
WHILE users <= 10
READ age
PRINT age.
users = users + 1
ENDWHILE
End
users = 1
NO
End users <= 10?
YES
read age
print age
users =users + 1
START
users = 0
WHILE users < 10
READ age
PRINT age. Be
users = users + 1 consistent
ENDWHILE
END
Problem:
Write a program that will calculate and print
the age of 10 persons, given their birth year. If
the age of the person is above 55, then the
program will print “Pencen”, otherwise, the
program will print “Kerja lagi”.