Presentation is loading. Please wait.

Presentation is loading. Please wait.

Multi-Dimensional Arrays

Similar presentations


Presentation on theme: "Multi-Dimensional Arrays"— Presentation transcript:

1 Multi-Dimensional Arrays
Multi-Dimensional Arrays

2 Multi-dimensional Arrays
Multi-dimensional Arrays The types of arrays discussed so far are all linear arrays. That is, they all dealt with a single dimension. But think about a situation where we want to store elements of a 3x4 matrix. The C language allows to have multi- dimensional arrays for this kind of situations. 

3 2 Dimensional Arrays - 2D Also called as 2D arrays.
2 Dimensional Arrays - 2D Column Index No. Also called as 2D arrays. Take the example of the 3x4 matrix. To store the elements of this we can declare a 2D array as follows: int matrix[3][4]; 1 2 2 6 9 4 5 12 10 16 7 3 18 Raw Index No. Raw Column

4 Assigning Values to a 2D Array Elements
Example 1: You can refer by row column indices int matrix[3][4]; matrix[0][0] = 2; matrix[0][1] = 6; Example 2: You can initialize row wise int matrix[3][4] = { {2,6,9,4}, {5,12,10,16}, {7,3,3,18} };

5 Array Exercise Declare a 2D array and store the values shown in the figure. Read the elements from the user After storing all the values, display the content of the matrix. Column Index No. 1 2 2 6 9 4 5 12 10 16 7 3 18 Raw Index No.

6 Homework Write a program to read values for a 2x3 matrix from a user and multiply with a scalar value and display the result. The scalar value also you must read from the user. Write a program to multiply two matrices of integers. 1st matrix is 3x2 and the 2nd matrix is 2x4. Display the result. Note : No need to read the matrices values from the user

7 Thank You !


Download ppt "Multi-Dimensional Arrays"

Similar presentations


Ads by Google