Year 11 Exam  >  Year 11 Notes  >  Computer for GCSE/IGCSE  >  Using Arrays

Using Arrays | Computer for GCSE/IGCSE - Year 11 PDF Download

Using Arrays

  • Arrays serve as efficient containers for multiple values of the same data type.
  • They find application in various tasks like maintaining student scores, computing averages, and handling inventory data.

Using variables in arrays

  • Variables can act as indices in arrays, enabling access and modification of elements through iterative checks.
  • This functionality proves valuable during array traversal using loops or conducting computations based on user input.

What is the first index value?

  • The initial index in an array can either start at 0 or 1, influenced by the programming language and personal choice.
  • Commonly used languages like Python, Java, and Visual Basic opt for 0 as the starting index.

Pseudocode example:

DECLARE scores[5] OF INTEGER
FOR i FROM 0 TO 4
INPUT scores[i]
ENDFOR

Python example:

scores = [0] * 5
for i in range(5):
scores[i] = int(input())

Java example:

int[] scores = new int[5];
Scanner scanner = new Scanner(System.in);
for (int i = 0; i < 5; i++) {
    scores[i] = scanner.nextInt();
}

Visual Basic example:

Dim scores(5) As Integer
For i As Integer = 0 To 4
   console.Writeline("Enter score: ")
    scores(i) = Console.ReadLine())
Next

Using Iteration

  • Loops enable the assignment of values into arrays by iterating through each element and assigning a value to it.
  • Similarly, iteration facilitates the retrieval of values from arrays by traversing through each element and executing operations or outputting the value.
  • Nested iteration proves valuable in handling multi-dimensional arrays like 2D arrays, where iteration through rows and columns is necessary.

Pseudocode example:

DECLARE scores[3][3] OF INTEGER
FOR i FROM 0 TO 2
   FOR j FROM 0 TO 2
      INPUT scores[i][j]
   ENDFOR
ENDFOR
FOR i FROM 0 TO 2
   FOR j FROM 0 TO 2
      OUTPUT scores[i][j]
   ENDFOR
ENDFOR

Python example:

scores = [[0] * 3 for _ in range(3)]
for i in range(3):
    for j in range(3):
        scores[i][j] = int(input())
for i in range(3):
    for j in range(3):
        print(scores[i][j])

Java example:

int[][] scores = new int[3][3];
Scanner scanner = new Scanner(System.in);
for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
        scores[i][j] = scanner.nextInt();
    }
}
for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
        System.out.print(scores[i][j] + " ");
    }
    System.out.println();
}

Visual Basic example:

Dim scores(2, 2) As Integer
For i As Integer = 0 To 2
    For j As Integer = 0 To 2
        Console.Writeline("Enter score: ")
        scores(i, j) = Console.ReadLine())
    Next
Next
For i As Integer = 0 To 2
    For j As Integer = 0 To 2
        Console.Write(scores(i, j) & " ")
    Next
    Console.WriteLine()
Next

The document Using Arrays | Computer for GCSE/IGCSE - Year 11 is a part of the Year 11 Course Computer for GCSE/IGCSE.
All you need of Year 11 at this link: Year 11
92 docs|30 tests

Top Courses for Year 11

92 docs|30 tests
Download as PDF
Explore Courses for Year 11 exam

Top Courses for Year 11

Signup for Free!
Signup to see your scores go up within 7 days! Learn & Practice with 1000+ FREE Notes, Videos & Tests.
10M+ students study on EduRev
Related Searches

Viva Questions

,

Using Arrays | Computer for GCSE/IGCSE - Year 11

,

pdf

,

study material

,

Important questions

,

practice quizzes

,

video lectures

,

Exam

,

past year papers

,

MCQs

,

Summary

,

ppt

,

Semester Notes

,

shortcuts and tricks

,

Free

,

Extra Questions

,

Using Arrays | Computer for GCSE/IGCSE - Year 11

,

Objective type Questions

,

Previous Year Questions with Solutions

,

mock tests for examination

,

Using Arrays | Computer for GCSE/IGCSE - Year 11

,

Sample Paper

;