Two Dimentional Array
-
Upload
sonya-rupa -
Category
Engineering
-
view
75 -
download
2
Transcript of Two Dimentional Array
![Page 1: Two Dimentional Array](https://reader036.fdocuments.in/reader036/viewer/2022083106/587603701a28ab4a508b60f5/html5/thumbnails/1.jpg)
Hamdard University BangladeshHamdard Nagar, Gazaria, Munshiganj
Presented by :Sonya Akter Rupa
ID: 3151610098th Batch 2nd SemesterDepartment of CSE
Presented to :
Md. Abdul MukibLecturer
Department of CSE
Two Dimensional Array
![Page 2: Two Dimentional Array](https://reader036.fdocuments.in/reader036/viewer/2022083106/587603701a28ab4a508b60f5/html5/thumbnails/2.jpg)
Presentation Outline¤ Array¤ 2 Dimensional Array¤ Storage allocation of 2D
Array¤ Declaration of 2D Array¤ Notation of 2D Array¤ Input of 2D Array ¤ Output of 2D Array¤ Addition of 2D Array¤ Subtraction of 2D Array¤ Application of 2D Array
![Page 3: Two Dimentional Array](https://reader036.fdocuments.in/reader036/viewer/2022083106/587603701a28ab4a508b60f5/html5/thumbnails/3.jpg)
Array
A single line of elements
Each element must be the same type
Consist of contiguous memory locations
The lowest address corresponds to the first element and
the highest address to the last element.
![Page 4: Two Dimentional Array](https://reader036.fdocuments.in/reader036/viewer/2022083106/587603701a28ab4a508b60f5/html5/thumbnails/4.jpg)
Array
Array 1 Array 2
![Page 5: Two Dimentional Array](https://reader036.fdocuments.in/reader036/viewer/2022083106/587603701a28ab4a508b60f5/html5/thumbnails/5.jpg)
Array
Array 1 Array 2
![Page 6: Two Dimentional Array](https://reader036.fdocuments.in/reader036/viewer/2022083106/587603701a28ab4a508b60f5/html5/thumbnails/6.jpg)
2 Dimensional Array
A two dimensional array has two subscripts/indexes.
The first subscript refers to the row, and the second, to the column.
Called as multi-dimensional array
![Page 7: Two Dimentional Array](https://reader036.fdocuments.in/reader036/viewer/2022083106/587603701a28ab4a508b60f5/html5/thumbnails/7.jpg)
Storage Allocation of 2D Array
Column 1 Column 2
Row 1
Row 2
Row 3
(0,0) (0,1)
(1,0) (1,1)
(2,0) (2,1)
Contagious memory is allocated to all the array elements.
![Page 8: Two Dimentional Array](https://reader036.fdocuments.in/reader036/viewer/2022083106/587603701a28ab4a508b60f5/html5/thumbnails/8.jpg)
Declaration of 2D Array
int hub[4][3]; the name of the array is hub the type of the array elements is integer the dimension to be 2 (two pairs of brackets [ ] ) the number of elements or size to be 4*3 = 12
![Page 9: Two Dimentional Array](https://reader036.fdocuments.in/reader036/viewer/2022083106/587603701a28ab4a508b60f5/html5/thumbnails/9.jpg)
Notation of 2D Array
hub = 31, 22, 33
54, 55, 56
Algebraic notation
Col 1 Col 2 Col 3
Row 1
Row 2 int hub[2][3] = {(31, 32, 33),(54, 55, 56)};
Array type Array nameArray dimension = 2
Two rows
Three columns
First row second row
C notation
![Page 10: Two Dimentional Array](https://reader036.fdocuments.in/reader036/viewer/2022083106/587603701a28ab4a508b60f5/html5/thumbnails/10.jpg)
Input of 2D Array Using nested for loops interactively or with data files. By increasing the index value of the array the elements can be entered in a 2d array.
int i,j,hub[3][4];printf("Enter the elements of hub :\n");for(i=0;i<3;++i) { for(j=0;j<4;++j){ scanf("%f",&hub[i][j]); }}
![Page 11: Two Dimentional Array](https://reader036.fdocuments.in/reader036/viewer/2022083106/587603701a28ab4a508b60f5/html5/thumbnails/11.jpg)
Output of 2D ArrayThe output of two-dimensional arrays should be in the form of rows and columns for readability.By increasing the index value of the array the elements stored at that index value are printed on the output screen.
for(i=0 ; i<3 ; i++) {
for(j=0 ; j<4 ; j++){ printf(“%d”,hub[i][j]);} printf(“\n”);
}
![Page 12: Two Dimentional Array](https://reader036.fdocuments.in/reader036/viewer/2022083106/587603701a28ab4a508b60f5/html5/thumbnails/12.jpg)
Addition of 2D ArrayLet two 2D array A and B of size of 2 X 3 is as follow:
Sum of two arrays is -
![Page 13: Two Dimentional Array](https://reader036.fdocuments.in/reader036/viewer/2022083106/587603701a28ab4a508b60f5/html5/thumbnails/13.jpg)
Subtraction of 2D ArrayLet two 2D array A and B of size of 2 X 3 is as follow:
Subtraction of two arrays is -
![Page 14: Two Dimentional Array](https://reader036.fdocuments.in/reader036/viewer/2022083106/587603701a28ab4a508b60f5/html5/thumbnails/14.jpg)
Application of 2D Array
Storing a table of dataAny kind of matrix processingImages are made up of picture elements or pixels and each pixel is one element of the 2D arrayModeling relationships, networks, and maps with a graph
![Page 15: Two Dimentional Array](https://reader036.fdocuments.in/reader036/viewer/2022083106/587603701a28ab4a508b60f5/html5/thumbnails/15.jpg)
Thanks To All