Topic 4.2.6 - Construct Pseudocode To Represent An Algorithm
Topic 4.2.6 - Construct Pseudocode To Represent An Algorithm
IB Computer Science
Topic 4.2
Connecting computational
thinking and program design
IB Computer Science
Topic 4.2: 4.2.1 - 4.2.9
Connecting computational
thinking and program design
IB Computer Science
Topic 4: 4.2.6
Construct pseudocode to
represent an algorithm.
Topic 4: 4.2.6
The following algorithm asks the user to enter five
integer values. Then, the values are stored in an array
and it is determined if the values entered are in
ascending or descending order. The program displays
a message indicating whether and how the elements
are ordered.
Topic 4: 4.2.6
I=0 output "The array is:"
SORTEDA = 1 loop I from 0 to 4
SORTEDD = 1 output SAMPLE[I]
SAMPLE = new Array() end loop
loop I from 0 to 4 if SORTEDA = 1 then
SAMPLE[I] = input("Enter the measurement“) output "The array is sorted in ASCENDING order“
end loop else
loop I from 0 to 3 output "The array is not sorted in ASCENDING order"
if SAMPLE[I] > SAMPLE[I+1] then end if
SORTEDA = 0 if SORTEDD = 1 then
end if output "The array is sorted in DESCENDING order"
if SAMPLE[I] < SAMPLE[I+1] then else
SORTEDD = 0 output "The array is not sorted in DESCENDING order"
end if end if
end loop
Topic 4: 4.2.6
User enters: 3, 5, 6, 4, 4.
Output 1:
The array is:
3
5
6
4
4
The array is not sorted in ASCENDING order
The array is not sorted in DESCENDING order
Topic 4: 4.2.6
User enters: 6, 5, 3, 2, 1.
Output 2:
The array is:
6
5
3
2
1
The array is not sorted in ASCENDING order
The array is sorted in DESCENDING order
Topic 4: 4.2.6
User enters: 2, 4, 78, 89, 99.
Output 3:
The array is:
2
4
78
89
99
The array is sorted in ASCENDING order
The array is not sorted in DESCENDING order