0
0
Cprogramming~30 mins

One-dimensional arrays in C - Mini Project: Build & Apply

Choose your learning style9 modes available
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
1
Create the sales array
Create an integer array called daily_sales with these exact values: 5, 8, 6, 7, 10, 9, 4.
C
Need a hint?

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

2
Create the total sales variable
Create an integer variable called total_sales and set it to 0.
C
Need a hint?

Initialize total_sales to zero before adding values.

3
Sum the sales using a for loop
Use a for loop with the variable i to iterate from 0 to 6 inclusive. Inside the loop, add daily_sales[i] to total_sales.
C
Need a hint?

Use total_sales += daily_sales[i]; inside the loop to add each day's sales.

4
Print the total sales
Use printf to print the text Total sales: followed by the value of total_sales and a newline.
C
Need a hint?

Use printf("Total sales: %d\n", total_sales); to print the result.