Page 61 - DCAP201_FUNDAMENTALS_OF_DATA_STRUCTURES
P. 61
Fundamentals of Data Structures
Notes
Figure 4.8: Schematic of a Column major representation of an Array
Col 0 Col 1 Col 2 ….. Col i
Task Compare and contrast row major representation and row major representation.
Self Assessment
Fill in the blanks:
6. Arrays with more than one dimension are called .............................. arrays.
7. A simple four-dimensional array of .............................. numbers, merely twenty elements
wide in each dimension, takes up 20^4 * 8, or 1,280,000 bytes of memory - about a megabyte.
8. ........................ arrays (and higher) are stored in the same way as the two-dimensional ones.
9. Two-dimensional arrays are called .............................. in mathematics.
10. If you have an m x n array, it will have .............................. elements and will require
m*n*element size bytes of storage.
11. A row is a horizontal list of elements and a .............................. is a vertical list of elements.
12. The.............................. of a dimension is the number of integers in its index set.
13. The pair of lengths m x n (read “m by n”) is called the.............................. of the array.
14. In the .............................. representation, the first row of the array occupies the first set of the
memory location reserved for the array, the second row occupies the next set, and so forth.
15. In the .............................. representation in which the first column of the array occupies the
first set of the memory locations reserved for the array.
Case Study Multidimensional Array in C
Write a C program to find sum of two matrix of order 2*2 using multidimensional arrays
where, elements of matrix are entered by user.
#include <stdio.h>
int main(){
float a[2][2], b[2][2], c[2][2];
int i,j;
printf(“Enter the elements of 1st matrix\n”);
/* Reading two dimensional Array with the help of two for loop. If there was an array of
‘n’ dimension, ‘n’ numbers of loops are needed for inserting data to array.*/
for(i=0;i<2;++i)
for(j=0;j<2;++j){
printf(“Enter a%d%d: “,i+1,j+1);
Contd...
54 LOVELY PROFESSIONAL UNIVERSITY