Two Dimentional Array

15
Hamdard University Bangladesh Hamdard Nagar, Gazaria, Munshiganj Presented by : Sonya Akter Rupa ID: 315161009 8 th Batch 2 nd Semester Department of CSE Presented to : Md. Abdul Mukib Lecturer Department of CSE Two Dimensional Array

Transcript of Two Dimentional Array

Page 1: Two Dimentional Array

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

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

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

Array

Array 1 Array 2

Page 5: Two Dimentional Array

Array

Array 1 Array 2

Page 6: Two Dimentional Array

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

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

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

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

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

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

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

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

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

Thanks To All