Array Traversal Patterns
📖 Scenario: You are working with a list of daily temperatures recorded over a week. You want to analyze these temperatures to find out which days were warmer than a certain threshold.
🎯 Goal: Build a program that traverses an array of temperatures, checks each temperature against a threshold, and collects the warmer temperatures into a new array.
📋 What You'll Learn
Create an array called
temperatures with exactly these values: 23, 27, 21, 30, 25, 28, 22Create an integer variable called
threshold and set it to 25Use a
for loop with an index variable i to traverse the temperatures arrayInside the loop, check if the current temperature is greater than
thresholdIf yes, add that temperature to a new array called
warmer_daysKeep track of the number of warmer days in an integer variable called
countPrint the contents of
warmer_days array separated by spaces💡 Why This Matters
🌍 Real World
Analyzing temperature data to find days warmer than a certain limit is common in weather forecasting and climate studies.
💼 Career
Understanding array traversal and conditional selection is fundamental for data processing tasks in software development and data analysis roles.
Progress0 / 4 steps
