Lecture-6 Data Structures CSE242
Lecture-6 Data Structures CSE242
Data Structures
c t ure
Le
6 By
Dr Sudeshna Chakraborty
Contents
• Array – Definition
• Multidimensional Array
• Multidimensional Array elements
• Multidimensional Array storing and accessing
Array
Array
• Collection of similar types of data items/elements
Multi
One
• Contiguous memory locations
Dimensional
Dimensional
• Multi dimensional
Multidimensional Array
• Collection of Linear arrays – 2D Arrays
• Collection of 2D - Arrays – 3D Arrays
Method 1: 9 10 11
int x[2][3][4] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 12 13 14
22, 23};
15 16 17
Better Method: 18 19 20
int x[2][3][4] =
{ 21 22 23
{ {0,1,2,3}, {4,5,6,7}, {8,9,10,11} },
{ {12,13,14,15}, {16,17,18,19}, 0 1 2
{20,21,22,23} } 3 412 513 14
}; 6 715 816 17
9 1018 1119 20
21 22 23
Assignment
Write a C program to find sum of specific elements of given 2D Array of nxn where n is odd:
1. Sum of both diagonals such that the central element is considered only once.
2. Sum of middle row and middle column elements such that the central element is considered only once.
3. Sum of corner elements.