1D Arrays - 1
1D Arrays - 1
1
1D Arrays
LO: Declare and use one-dimensional (1D) .
Keywords: Array index, Upper bound, Lower bound
CCL: Maths
01 02 03
Need of a Continuous Less
single memory processing
variable for locations time.
multiple are
data items available.
• One dimensional
(1D) array
• Two dimensional
(2D) array
Sol:
FOR index 1 TO 5
ARR[index] ARR[index] +1
NEXT index
LO: To declare and use 1D arrays
Putting data into an array(Population of
array) 11
Example 1
• Store the colour "red" in the first position of the array named Colour:
• Colour [O] “red”
• Example 2
• Store the colour "yellow" in the second position of the array named Colour:
• Colour[1] “yellow”
• Example 3
• Store the number 20 in the sixth position of the array named Numbers:
• Numbers[5] 20
LO: To declare and use 1D arrays
Getting data out of an array 12
Example 1
• Output the first value in the array Colours:
• OUTPUT(Colours[0])
Example 2
Store the second value in the array Colours in a variable:
TheColour Colours[1]
Example 3
Add 10 to the third value in the array Numbers:
Value
LO: 10and
To declare + Numbers[2]
use 1D arrays
Using iteration to read and write 13
Example 1
Output all 10 elements in the array Colours:
FOR Count 0 TO 9
OUTPUT(Colours[Count])
NEXT Count
Example 2
Ask the user to input 20 numbers and store each in the array Numbers:
FOR Counter O TO 19
OUTPUT ("Enter a number")
INPUT Numbers[Counter]
NEXT Counter
LO: To declare and use 1D arrays
Data types 14
Searching the values in the array values that has 50 values, for the data
input by the user:
• DECLARE Values: ARRAY[0:49] OF INTEGER
• DECLARE ValueToFind, Count :INTEGER
• OUTPUT "Enter the value to find"
• INPUT ValueToFind
• FOR Count 0 TO 49
• IF Values[Counter] = ValueToFind
• THEN
• OUTPUT("Found it")
• ENDIF
• NEXT
LO: Count
To declare and use 1D arrays
TASK 17
1. Explain the difference between a variable and an array.
4. To
LO: Write a program
declare toarrays
and use 1D add together all 100 elements in a 1-dimensional array
SOL 18
• https://lalacomputersci.wordpress.com/arrays/
• http://www.bitsofbytes.co/arrays.html