Array initialization
📖 Scenario: You are helping a small store keep track of the prices of 5 popular fruits. You want to store these prices in an array so you can use them later for calculations.
🎯 Goal: Create an array to hold the prices of 5 fruits, set a threshold price, find which fruits are more expensive than the threshold, and print those prices.
📋 What You'll Learn
Create an array called
prices with exactly these values: 120, 80, 150, 90, 200Create an integer variable called
threshold and set it to 100Use a
for loop with variable i to check each price in prices and create a new array expensive that contains only prices greater than thresholdPrint each price in the
expensive array on its own line💡 Why This Matters
🌍 Real World
Arrays are used to store lists of data like prices, scores, or measurements in many programs.
💼 Career
Understanding array initialization and filtering is a basic skill for programming jobs that handle data processing.
Progress0 / 4 steps