

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Instructions for completing a programming assignment in c that involves using 2-dimensional arrays. The assignment includes downloading a source file and data file, writing functions to find the player with the most hits and calculate batting averages, and displaying all statistics for all players. The document also explains how to declare and assign values to 2-dimensional arrays in c.
Typology: Assignments
1 / 3
This page cannot be seen from the preview
Don't miss anything!


Name: Sec: 06/22/
Two dimensional arrays can be thought of as tables of data. A familiar example of a table of data is the spreadsheet, such as Microsoft Excel, where you arrange data into rows and columns. To declare a 2-Dimensional array in C, we do the following: const int NUM_ROWS = 8; const int NUM_COLUMNS = 5; int table[NUM_ROWS][NUM_COLUMNS]; The above, as you can probably guess, creates an array called table, that can hold/ represent a table with 8 rows and 5 columns. Of course, by changing the named constants NUM_ROWS and/or NUM_COLUMNS, you can change the size of the table that is being created and represented. However, unlike a spreadsheet, 2- dimensional arrays in C must always start at index 0 for both the row index and the column index. By convention, the first index is used to index the row number, and the second index the column number. This convention is somewhat arbitrary, they could be reversed, but in most of mathematics and programming you will see people using this ordering when working with 2-dimensional tables, so it is a good idea to just memorize this ordering. So, a visual representation of the 2-dimensional table variable, declared above, would be: table [0] [1] [2] [3] [4] [0] [1] [2] [3] [4] 25 [5] [6] [7] To assign a value into a 2-dimensional table, we do the same as for a 1- dimensional array, except we specify 2 indexes, the row, column. So, to assign
the value 25 to the cell shown in the table, which is in the row with index 4 and the column with index 1, we would do: table[4][1] = 25; In this program, you will use and manipulate data in a 2-dimensional array.
Become familiar with using 2-dimensional array to solve problems. Also, learn how to correctly pass a 2-dimensional array to a function.