Working with One-Dimensional Arrays in C
📖 Scenario: You are helping a small store keep track of the number of items sold each day over a week. You will use a one-dimensional array to store these daily sales numbers.
🎯 Goal: Build a simple C program that stores daily sales in an array, calculates the total sales for the week, and prints the total.
📋 What You'll Learn
Create an integer array named
daily_sales with exactly 7 elements representing sales for each day of the week.Create an integer variable named
total_sales to hold the sum of all sales.Use a
for loop with the variable i to iterate over the daily_sales array.Add each element of
daily_sales to total_sales inside the loop.Print the value of
total_sales using printf.💡 Why This Matters
🌍 Real World
Stores and small businesses often track daily sales to understand their performance and plan inventory.
💼 Career
Knowing how to use arrays and loops is essential for programming tasks involving data collection and processing in many software development jobs.
Progress0 / 4 steps