M2 Guide
M2 Guide
ALGORITHM
ALGORITHM OVERVIEW
• Plan the algorithm that will transform the problem’s input into its output.
• Write the algorithm in the Processing column of the Input-Process-Output (IPO) chart.
• Each instruction in the algorithm will describe an action that the computer needs to
take.
ALGORITHM OVERVIEW
• Most algorithms begin with instruction to enter the input items into the computer.
• Next, record instructions to process the input items to achieve the problem’s output.
• The processing typically involves performing one or more calculations using the input items.
• Most algorithms end with instruction to display, print, or store the output items.
• Display, print, and store refer to the computer screen, printer, and a file on a disk, respectively.
PSEUDOCODE
• Pseudocode is called false code because, it has no syntax like any of the programming language
and thus can’t be compiled or interpreted by the computer.
• It is not standardized.
• Every programmer has his or her own version, but you will find some similarities among other
versions.
WRITING A PSEUDOCODE
• In Pseudocode, keywords are used to indicate common input-output and processing operations.
They are written fully in uppercase.
• It also used mathematical, relational and logical operators to express arithmetic and logical
operations.
• When writing pseudocode, we assume that the order of execution of the statements is from top
to bottom. This changes when using control structures, functions and exception handling.
WRITING A PSEUDOCODE
KEYWORDS:
• INPUT, ENTER, READ / GET : This is data retrieved from the user through typing or through an
input device.
• PRINT, OUTPUT, DISPLAY, SHOW: This will show your output to a screen or the relevant output
device.
COMMON OPERATORS:
• Assignment: ← or :=
Example:
c ← 2πr, c := 2πr
• Arithmetic: +, −, ×, /, mod
Example:
a + b, x – y, m x n,
s / t, num mod 2
KEYWORDS in CONDITIONAL:
During algorithm development, we need statements which evaluate expressions and execute
instructions depending on whether the expression evaluated to True or False.
• IF — THEN – ENDIF
• IF – ELSE IF — ENDIF
Problem Specification 1:
Ms. Noreen wants a program that will calculate and display the amount she should tip a waiter at a
restaurant. Tip can be computed by multiplying the total bill and the tip (using a percentage).
Problem Specification 2:
Make a program that will display the lowest and highest of two integers entered by the user using if-else
statement.
Problem Specification 3:
Make a program that will ask the user to choose from letters A to C then display the equivalent fruit
starting from the selected letter using case statement.
ITERATION: FOR LOOP
Problem Specification 5:
Make a program that will display the sum of three input numbers using for loop statement
Problem Specification 4:
Make a program that will display the sum of three input numbers using while loop statement
Make a program that will display the sum of three input numbers using do-while loop statement
FLOWCHART OVERVIEW
• Program Flowchart is a diagram that uses a set of standard graphic symbols to represent the
sequence of coded instructions fed into a computer, enabling it to perform specified logical and
arithmetical operations.
FLOWCHART SYMBOLS
FLOWCHART STRUCTURES
• sequence
• selection/conditional
• loop.
2. Find the largest among three different numbers entered by the user.
3. Find all the roots of a quadratic equation ax2+bx+c=0