1D Array Tutorial Questions
1. Declare and Print
o Declare an integer array of size 5. Assign values and print all elements using a
loop.
2. Initialization
o Create an array using: int[] numbers = {5, 10, 15, 20, 25}; and print each
element.
3. Default Values
o Declare an integer array of size 4 but do not assign values. Print all elements
and observe the default values.
4. Sum of Elements
o Ask the user to enter 5 numbers. Store them in an array and calculate the
sum of all elements.
5. Average Calculation
o Modify the above program to also calculate the average of the numbers.
6. Find Largest & Smallest
o Write a program to find the largest and smallest number in a 1D array of 6
elements.
7. Search a Number
o Ask the user to input a number. Check whether the number exists in the
array. Print "Found" or "Not Found".
8. Count Occurrences
o Count how many times a specific number appears in the array.
9. Even & Odd Count
o Count the number of even and odd numbers in an array of 10 integers.
10. Reverse an Array
o Reverse the elements of a 1D array and print the reversed array.
11. Remove an Element
o Ask the user for an index, remove the element at that index, and print the
new array (ignore resizing for now).
Scenario Question 1: Student Marks Analyzer
Scenario:
You are a teacher who wants to analyze the marks of 10 students in a recent test. You need
a program to help you understand the class performance.
Tasks:
1. Ask the user to input the marks of 10 students and store them in a 1D array.
2. Display all the marks.
3. Calculate and print the average marks of the class.
4. Find and print the highest and lowest marks.
5. Count how many students scored above the average.
6. Reverse the array and print the marks in reverse order.
Hints:
• Use a loop to read and store marks.
• Use another loop to calculate the sum and find min/max.
• To reverse, start from the last element and move to the first.
Scenario Question 2: Shopping Cart Total
Scenario:
You are designing a simple checkout system for a small store. Customers can buy multiple
items, and you need a program to calculate the total bill and analyze their purchases.
Tasks:
1. Ask the user how many items they bought and store the number in a variable n.
2. Let the user input the price of each item and store them in a 1D array.
3. Display all the prices entered.
4. Calculate and print the total bill.
5. Find and print the most expensive item.
6. Count how many items cost more than RM50.
Hints:
• Use a loop to input the item prices.
• Use a loop to calculate the total and find the maximum.
• Use a loop with a condition to count items over RM50.