 Consider this table of quarterly sales over three years. Consider this table of quarterly sales over a three-year period. This data is best represented as a two-dimensional array. When declaring this array in C, you follow the array name with two sets of square brackets to specify the array's dimensions. The number in the first set of brackets gives the number of rows, and the number in the second set of brackets gives the number of columns. The braces that initialize the array contain each row of the array in its own set of braces. To access an individual element of an array, you also need to use two sets of square brackets with the row number first, then the column number. At this moment, it's not important to know how C stores arrays in memory, but the issue will come up later when we talk about a concept called pointers. So, for the sake of completeness, we'll note that arrays are stored in row major order, linearly one row after the other. Now, let's write code to get the grand total of all the elements of the array. If we were doing algebra, we'd get the total of the two-dimensional array elements with a double summation like this. That translates into a nested loop in C. Let's start by setting the grand total to zero. The outer loop will traverse the rows. Most books will use i and j as their loop index variables. That's a holdover from algebra and from a programming language called Fortran. I'm not going to do that. Instead, I'll use row as my counter variable rather than i. This makes the code much more understandable. I'll start the row at zero, while the row is less than three. At the end of the loop body, I add one to row, and now the inner loop to iterate over the columns. For column is zero, column less than four, and increment the column, and the body of the nested loop will take the grand total, plus and becomes the sales at the given row and column, then print out the grand total properly labeled. Since everything is in thousands of dollars, let's build that and run it, and there's our grand total. Now let's get the totals for each year by summing all the items in each row, one row at a time. First, let's establish our base year as 2018. There's something new here. Const. This is a keyword that we use to define a constant. Once the variable is initialized, the value can no longer be changed. Many style guidelines recommend using all uppercase for constant names to distinguish them from variables whose values can be modified, and I'm following that guideline as well. We'll now run a loop for all of the rows. When we start a new row, the total for that year is zero. That means we set the double yearly total to zero inside of the loop. Now we traverse the columns, and inside this loop, we set the yearly total, plus and becomes the sales for the given row and column. Now that we've gone and added up all of the columns in a particular row, we've finished that row and it's time to print it out. That'll be our year. The year is the base year plus the row, and the value we want to print out is our yearly total. This printf is inside the outer loop. We want it to happen every time we finish a row. Let's build and run, and there are the yearly totals. Finally, here's another loop to print the quarterly totals. This will involve summing up the columns, which means that the outer loop will have to iterate over the columns instead of the rows. At the start of each column, our quarterly total is zero, and now we iterate over the rows. Our inner loop body sets the quarterly total to plus and become the sales at the given row and column. It's very important to note that when you access the array element, you always put the row first, even though it may not be the index for the outer loop. And here's a place where naming our loop variables row and column instead of i and j really pays off. Once we've added up all the rows, we can print our result for that column. The first placeholder will be our quarter number, and the second placeholder will be our money. Our quarters, which are the columns, start numbering at zero. But people expect to see the first quarter, second quarter, third and fourth quarter. That means we'll fill in our first placeholder with instead of column, column plus one, and the quarterly total fills in the second placeholder. Let's close our outer for loop, build, and execute. The only thing I want to do now is make our output a little bit more readable, and that will be by putting in an extra blank line after each section. After this second loop is done, we want to print one new line. Let's comment that, copy that here, build, and run. And there's the result. You're not limited to one in two-dimensional arrays in C. Here, for example, is an array that shows quarterly sales figures for three regions over three years. Although you can declare four, five, and even more dimensional arrays in C, you should think carefully before doing so. Those may not be the best data structures for solving your problem. In most cases, you'll find one and two-dimensional arrays to be the ones you use the most.