Practice

Odd and Even Index Totals

2024/May/June·Variant 1·Q4
MEDIUMArrays

Adapted from Cambridge International AS & A Level Computer Science (9618), May/June 2024 Paper 21, Question 4.

A global array Data stores integer elements. Write function Check() to total the elements in odd index locations and even index locations. Return:

  • "Odd" if the odd-index total is greater
  • "Even" if the even-index total is greater
  • "Same" if the totals are equal

The original exam question uses 100 elements. This practice version uses 10 elements to keep test cases readable.

Input: 10 integers for Data[1] to Data[10]. Output: Odd, Even, or Same.

Example:

Input:  5
        1
        5
        1
        5
        1
        5
        1
        5
        1
Output: Odd
Premium is coming soon. All grading features are currently unlocked.

Sample Test Cases

Test 1: Odd index total greater
Inputs: 5, 1, 5, 1, 5, 1, 5, 1, 5, 1
Expected: Odd
Test 2: Even index total greater
Inputs: 1, 5, 1, 5, 1, 5, 1, 5, 1, 5
Expected: Even
Test 3: Totals equal
Inputs: 1, 1, 2, 2, 3, 3, 4, 4, 5, 5
Expected: Same