Working with Two-Dimensional Arrays in C
📖 Scenario: You are helping a small shop owner keep track of daily sales for different products over a week. The sales data is stored in a table where each row represents a product and each column represents a day of the week.
🎯 Goal: Create a program that stores sales data in a two-dimensional array, calculates the total sales for each product, and then prints the totals.
📋 What You'll Learn
Create a two-dimensional array called
sales with 3 rows and 7 columns to store sales numbers.Create an integer variable called
total to hold the sum of sales for each product.Use a
for loop with variable i to go through each product (row).Use a nested
for loop with variable j to go through each day (column) for the current product.Calculate the total sales for each product by adding the daily sales.
Print the total sales for each product using
printf.💡 Why This Matters
🌍 Real World
Two-dimensional arrays are useful for storing tables of data like sales, schedules, or pixel colors in images.
💼 Career
Understanding how to work with two-dimensional arrays is important for jobs involving data analysis, software development, and any task that requires managing grid-like data.
Progress0 / 4 steps