You are on page 1of 27

SD 101A

Basic Programming
Version 2 Version 3a

1) Input the value of num1 1) Input num1

2) Input the value of num2 2) Input num2

3) sum gets the sum of num1 3) sum = num1 + num2


and num2
4) ave gets the result of sum 4) ave = sum / 2
divided by two
5) Print ave 5) Display ave

Prepared by: adcantara-sbpolinar


Version 2 Version 3b

1) Input the value of num1 1) Input num1

2) Input the value of num2 2) Input num2

3) sum gets the sum of num1 3) ave


sum==(num1
(num1++num2)
num2)//22
and num2
4) ave gets the result of sum 4) Display ave
divided by two
5) Print ave

Prepared by: adcantara-sbpolinar


Version 2 Version 3b
3c

1) Input the value of num1 1) Input num1 and num2

2) Input the value of num2 2) Input


ave = num2
(num1 + num2) / 2

3) sum gets the sum of num1 3) sum = (num1


Display ave + num2) / 2
and num2
4) ave gets the result of sum 4) Display ave
divided by two
5) Print ave

Prepared by: adcantara-sbpolinar


1. Pseudocode – English phrases are used to describe
the algorithm
2. Flowchart – pictures that employ specifically
defined shapes are used
3. Formula – mathematical equations are used
4. Program – programming languages (e.g. C) are used

Prepared by: sbpolinar


Prepared by: sbpolinar
Another way to represent an algorithm.
Is a pictorial representation and it allows us to
easily visualize the structure of the algorithm.
Flowcharts begin with the start symbol and end
with a stop symbol.

Prepared by: sbpolinar


A Flowchart is a pictorial representation and it allows
us to easily visualize the structure of the algorithm.

The idea is to represent each operation using any


one of the symbols shown below.

Input/Output
Start / stop Decision Connector

Process Initialization Predefined Process Flow lines

11/12/2016 Preparedby:
Prepared by: Marilou
sbpolinar
M. Iway, MIT 8
Flowchart
Flow Lines
• indicated by straight lines with arrows
to show the direction of data flow

• the arrowhead is sometimes not shown


when the direction of flow is clear

Prepared by: Angie M. Ceniza, MIT


Flowchart
Flow Lines
• used to connect blocks by exiting from
one and entering another

Prepared by: Angie M. Ceniza, MIT


Flowchart
Terminal block
• ovals or rounded rectangles are used to
indicate the start and the end of a
module or program

• an oval is labeled with the name of the


module at the start ; the end is
indicated by the word end or stop for
the top or Control Module

Prepared by: Angie M. Ceniza, MIT


Flowchart
Terminal block
• a start has no flow lines entering it and
only one exiting it; an end or exit has
one flow line entering it but none
exiting it

START

END

Prepared by: Angie M. Ceniza, MIT


Flowchart
Initialization block
• used for declaring / initializing variables
needed to solve a certain process

• Declaration
– binding of an identifier to the
information that relates to it
– stating a variable name to be used

Prepared by: Angie M. Ceniza, MIT


• Initialization
Flowchart
– to set (a starting value of a variable)
– to prepare (a computer or a printer)
for use; boot
– to format (a storage medium, such as
a disk)

X = 10
Y = 25

Prepared by: Angie M. Ceniza, MIT


Flowchart
Process block
• the rectangle indicates a processing
block, for such things as calculations,
opening and closing files, and so forth
• a processing block has one entrance
and one exit

X=Y+Z
A = 18
B=A-2

Prepared by: Angie M. Ceniza, MIT


Flowchart
Input/Output block
• the parallelogram indicates input to and
output operations
• an I/O block has one entrance and only
one exit

Get X Display X

Prepared by: Angie M. Ceniza, MIT


Flowchart
Decision block

• the diamond indicates a decision


• it has one entrance and exactly two exits
from the block
• one exit is the action when the resultant
is TRUE and the other exit is the action
when resultant is FALSE

Prepared by: Angie M. Ceniza, MIT


Flowchart
Decision block

T F
Condition

Action when Action when


TRUE FALSE

Prepared by: Angie M. Ceniza, MIT


Flowchart
Connectors
• the circle is used as a connection point
between two sections of a flowchart
that are not adjacent or closely located
to each other

Prepared by: Angie M. Ceniza, MIT


Flowchart

Connectors
Note: These connectors should be used
as little as possible. They should only be
used to enhance readability. Overuse,
however, decreases readability and
produces a cluttered effect.

Prepared by: Angie M. Ceniza, MIT


A
Start
1. Input x
2. Input y Output Ave
Input x
3. sum = x+y
4. Ave = sum/2 Ave%2 False
Display
Input y ==0
5. Output Ave “ODD”

6. If (Ave%2==0) True
sum = x+y Display
Then Output “EVEN”
“EVEN”
Else Output “ODD”
Ave = sum/2
Stop

A
Start

1. Input x, y
Input x and y
2. sum = x+y
Ave = sum/2 sum = x+y
3. Output Ave Ave = sum/2

4. If (Ave%2==0) Display Ave


Then Output “EVEN”
Else Output “ODD”
Ave%2 False
Display “ODD”
==0
True
Stop
Display “EVEN”
Prepared by: adcantara-sbpolinar
1. Input N
2. x=1
3. Repeat
While (x the
<= N)following N times
a. Output x
b. x = x+1

Prepared by: sbpolinar


End

Prepared by: sbpolinar


A.
1. Input amount
2. if (amount >= 49.35)
totalLiters = amount/49.35
Print totalLiters
else print “We cannot sell that volume.”

Prepared by: sbpolinar


B.
1. count = 1, sumEven = 0, sumOdd = 0
2. while (count <= 20)
a. Input num
b. if (num%2 == 0)
sumEven = sumEven + num
else sumOdd = sumOdd + num
c. count = count +1
3. Output “The sum of all even numbers is”, sumEven,
“and the sum of all odd numbers is”, sumOdd
Prepared by: sbpolinar
3. Create a pseudocode and flowchart that
will allow user to input an integer N and
displays the number of digits in N.
Input 23475
Output 5

Prepared by: sbpolinar

You might also like