Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 5

1.

Create a flowchart that will arrange the values of A, B and C in ascending order
where
Variable A will get the lowest value and variable C gets the highest value. The values
of the variables are: A = 20, B = 15 and C = 25.

Given variables and their values:

20 15 25

A B C
Output Requirement

15 20 25

A B C
We need a new variable temp to temporarily hold the data of B so that during the
process, the data is preserved. Since we know that we have to save first the data of B
before it accepts the data from A, let us move the data of B to temp.

20 15 25 15

A B C temp
We can now destroy the data on B since it is now saved on temporary variable.

20 20 25 15

A B C temp
The first objective of moving the data of A to B was accomplished and we can now save
the data from Temp to A to accomplish the problem.

15 20 25 15

A B C temp
The final data of the variables after the final swapping process is:

15 20 25 15
A B C temp
Flowchart:

START

A = 20
B = 15
C = 25
Temp = 0

Temp = B

B=A

A = Temp

STOP
2. Create a flowchart that will arrange the values of A, B, C and D in Highest to Lowest
order where variable A gets the highest value and variable D gets the lowest value. The
values of the variables are: A = 6, B = 12, C = 15, and D = 9. Show your analysis.

Analysis:
The problem is to arrange the data in Highest to Lowest order. It also has a clear
direction on where to save the arranged values, variable A should get the highest value
(15) and variable D should get the lowest value (6). We know from the given values that
the highest value stored in variable C should be placed in variable A, and logically we
cannot immediately move the data from C to A because we might destroy the data in A.
Swapping the contents would need additional variable to temporary hold the data that
we want to swap and to preserve the data. Variable temp will initialize to function as
temporary holder of the data to another. The solution using the swapping technique is
illustrated as follows:

6 12 15 9

A B C D

Output Requirement

15 12 9 6

A B C D

Given variables and their values:


The presence of variable Temp is for the preservation of data that will be used to save
the data on variable A for A to accept Highest number.

6 12 15 9 0

A B C D temp
Since the data of Variable A is now saved, we can now destroy the data of A and move
the Highest.

6 12 15 9 6

A B C D temp

The value of variable C, 15, the highest value is now stored on variable A, Logically,
both C and A have the same values now and we can now destroy the value of variable
C. Since variable B has the second highest value, variable B will not be part of the
process of swapping. Let us now move the data on variable D to variable C.

15 12 15 9 6

A B C D temp

To complete the solution, the data kept on the temporary variable should be placed to
variable D.

15 12 9 9 6

A B C D temp

The final data of the variables after the final swapping process is:

15 12 9 6 6

A B C D temp
Flowchart:

START A

A=6
C=D
B = 12
C = 15
D=9
Temp = 0

Temp = A

D = Temp

A=C

STOP

You might also like