Arrays
Arrays
Objectives
i. Declare and use one-dimensional arrays
• A playlist of songs
Example to understand
This is a four story building.
Ground floor and three floors.
Ground floor is considered as 1st ,first floor as 2nd , second floor as 3rd
and third floor as 4th .
Similarly the first index (0) in an array is considered as 1st position
/Location where element/data will be stored.
Example to understand the need of Array :
Pseudo code to Input test scores of 3 students
• Input score1
• Input score2
• Input score3
Need to declare three variables to input the values.
Example :
In previous example, test scores of students were needed to input , test
score is an integer type of data and it was required to save 10 elements, so
the array will be declare as :
DECLARE testscore[1:10] of integer
Next count
Read / output / Print values from Array
Example
0 1 2 3 4 5 6 7 8 9
6 12 34 65 78 90 44 34 87 23
For ...to. Next loop can be used to read the entire array. The program will be :
For count = 1 to 10
Print testscore [count]
Next count
Complete pseud code to input 10 test scores of students and display on the screen
using an Array
For count = 1 to 10
Print testscore [count] Read from Array and display
Next count
Any Question?