0
0
Cprogramming~15 mins

Array traversal in C - Mini Project: Build & Apply

Choose your learning style9 modes available
Array traversal
📖 Scenario: You are working with a list of daily temperatures recorded over a week. You want to look at each temperature one by one to understand the weather pattern.
🎯 Goal: Build a simple C program that stores temperatures in an array and then goes through each temperature to print it out.
📋 What You'll Learn
Create an integer array named temperatures with exactly 7 values: 23, 25, 22, 20, 24, 26, 21
Create an integer variable days and set it to 7
Use a for loop with the variable i to traverse the temperatures array from index 0 to days - 1
Print each temperature value inside the loop using printf
💡 Why This Matters
🌍 Real World
Arrays are used to store lists of data like temperatures, scores, or names so you can easily access each item one by one.
💼 Career
Understanding how to traverse arrays is a basic skill needed in many programming jobs, including software development, data analysis, and embedded systems.
Progress0 / 4 steps
1
Create the temperatures array
Create an integer array called temperatures with these exact values: 23, 25, 22, 20, 24, 26, 21.
C
Need a hint?

Use curly braces {} to list the values inside the array.

2
Set the number of days
Create an integer variable called days and set it to 7.
C
Need a hint?

Just create a simple integer variable and assign the number 7.

3
Traverse the array with a for loop
Use a for loop with the variable i to go from 0 to days - 1 and access each element of temperatures.
C
Need a hint?

Start i at 0 and continue while it is less than days.

4
Print each temperature
Inside the for loop, use printf to print each temperature from the temperatures array followed by a newline.
C
Need a hint?

Use printf("%d\n", temperatures[i]); to print each temperature on its own line.