SlideShare a Scribd company logo
Structured Programming Language
2 Dimensional Array
Mohammad Imam Hossain,
Lecturer, CSE, UIU
Array
• A data structure that can store a fixed-
size sequential collection of elements of
same type.
• More useful to think as a collection of
variables of the same type.
• Arrays we have consider up to now are
one dimensional arrays, a single line of
elements.
Programming Language Rating
90 85 85 90 80 20 20
95 90 85 80 90 30 10
C C++ C# java python ruby perl
Columns representing programming languages
Differentpersons
Why 2 D
• Matrix calculator
• Any kind of board game (chess, tic-tac-toe, number
puzzle, word puzzle, minesweeper etc.)
• Graph representation
• Image representation
• Excel data
• Database table to store information
etc………
Declaration
int x ; ///declaring integer type variable x
Declaration
int x ; ///declaring integer type variable x
int x[100] ; ///declaring 1D array of 100 integers
Declaration
int x ; ///declaring integer type variable x
int x[100] ; ///declaring 1D array of 100 integers
int x[100] [50] ; ///declaring 100 1D array each of 50 integers
///i.e. a 2D array of 100 rows and 50 columns
Declaration
int x ; ///declaring integer type variable x
int x[100] ; ///declaring 1D array of 100 integers
int x[100] [50] ; ///declaring 100 1D array each of 50 integers
///i.e. a 2D array of 100 rows and 50 columns
datatype arrayName [Max_rows][Max_cols] ;
• datatype = any valid C data type.
• arrayName = any valid C identifier.
2 D Array
int a[Max_rows] [Max_cols] ;
a[0][0] a[0][1] a[0][2] a[0][3]
a[1][0] a[1][1] a[1][2] a[1][3]
a[2][0] a[2][1] a[2][2] a[2][3]
Col 0 Col 1 Col 2 Col 3 Max_cols-1
Row 0
Row 1
Row 2
Max_rows-1
Initialization
int arr[3][4]={1 , 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};
int arr[3][4]={
{1,2,3,4},
{5,6,7,8},
{9,10,11,12}
};
Or, 1 2 3 4
5 6 7 8
9 10 11 12
Accessing 2D array
1 2 3 4
5 6 7 8
9 10 11 12
Row 1 >>>
Col 1
int var=arr[1][1]; /// the value of variable var is 6
Accessing 2D array
1 2 3 4
5 6 7 8
9 10 11 12
Row 1 >>>
Col 1
int var=arr[1][1]; /// the value of variable var is 6
scanf("%d",&arr[2][3]); /// let, input is 100
printf("%d",arr[2][3]);
100
Accessing 2D array
1 2 3 4
5 6 7 8
9 10 11 12
Row 1 >>>
Col 1
int var=arr[1][1]; /// the value of variable var is 6
scanf("%d",&arr[2][3]); /// let, input is 100
arr[0][0] = 20 ;
printf("%d",arr[2][3]);
100
20
Taking Input
#include <stdio.h>
#define ROW 5
#define COL 3
int main()
{
int arr[ROW][COL];
int r,c;
for(r=0;r<ROW;r++){
for(c=0;c<COL;c++){
scanf("%d", &arr[r][c]);
}
}
printf("Completedn");
///other codes......
return 0;
}
Showing 2D array
int r,c;
for(r=0;r<ROW;r++){
for(c=0;c<COL;c++){
printf("%d ",arr[r][c]);
}
printf("n"); ///showing the next row in a different line
}

More Related Content

PPT
Lecture 16 - Multi dimensional Array
PPTX
Array in c
PPTX
Basic array in c programming
PPSX
C Programming : Arrays
PPTX
Array,MULTI ARRAY, IN C
PPTX
Arrays in c
PPTX
Array in c
PPTX
Array in C
Lecture 16 - Multi dimensional Array
Array in c
Basic array in c programming
C Programming : Arrays
Array,MULTI ARRAY, IN C
Arrays in c
Array in c
Array in C

What's hot (20)

PPT
Multidimensional array in C
PPTX
Introduction to Array ppt
PPT
Arrays in c
PDF
Lecture17 arrays.ppt
PPTX
Arrays in c language
PDF
Arrays In C
PPTX
Array in C
PDF
Day 2b i/o.pptx
PPT
Lecture 15 - Array
PPTX
PPTX
Array in c++
PPT
One dimensional 2
PPT
Array in c
PDF
Day 2 repeats.pptx
PPT
Presentation about arrays
PPTX
concept of Array, 1D & 2D array
PPTX
Two dimensional arrays
PPT
Two dimensional array
PPTX
C++ lecture 04
PPTX
Arrays basics
Multidimensional array in C
Introduction to Array ppt
Arrays in c
Lecture17 arrays.ppt
Arrays in c language
Arrays In C
Array in C
Day 2b i/o.pptx
Lecture 15 - Array
Array in c++
One dimensional 2
Array in c
Day 2 repeats.pptx
Presentation about arrays
concept of Array, 1D & 2D array
Two dimensional arrays
Two dimensional array
C++ lecture 04
Arrays basics
Ad

Similar to SPL 12 | Multi-dimensional Array in C (20)

PPT
358 33 powerpoint-slides_5-arrays_chapter-5
PDF
02 arrays
PPTX
Module_3_Arrays - Updated.pptx............
PPT
Array THE DATA STRUCTURE. ITS THE STRUCT
PPT
Chapter 10.ppt
PPTX
2. Array in Data Structure
PPTX
PPTX
Arrays 1D and 2D , and multi dimensional
PPTX
Data Structure_Array_and_sparse matrix.pptx
PPTX
UNIT-5_Array in c_part1.pptx
PPTX
Programming fundamentals week 12.pptx
PPT
PPTX
BHARGAVIARRAY.PPT.pptx
PPT
array2d.ppt
PPTX
Unit4pptx__2024_11_ 11_10_16_09.pptx
PPTX
C_Arrays.pptx
PPTX
PPTX
C (PPS)Programming for problem solving.pptx
PDF
SPL 10 | One Dimensional Array in C
PPTX
Array 2 hina
358 33 powerpoint-slides_5-arrays_chapter-5
02 arrays
Module_3_Arrays - Updated.pptx............
Array THE DATA STRUCTURE. ITS THE STRUCT
Chapter 10.ppt
2. Array in Data Structure
Arrays 1D and 2D , and multi dimensional
Data Structure_Array_and_sparse matrix.pptx
UNIT-5_Array in c_part1.pptx
Programming fundamentals week 12.pptx
BHARGAVIARRAY.PPT.pptx
array2d.ppt
Unit4pptx__2024_11_ 11_10_16_09.pptx
C_Arrays.pptx
C (PPS)Programming for problem solving.pptx
SPL 10 | One Dimensional Array in C
Array 2 hina
Ad

More from Mohammad Imam Hossain (20)

PDF
DS & Algo 6 - Offline Assignment 6
PDF
DS & Algo 6 - Dynamic Programming
PDF
DS & Algo 5 - Disjoint Set and MST
PDF
DS & Algo 4 - Graph and Shortest Path Search
PDF
DS & Algo 3 - Offline Assignment 3
PDF
DS & Algo 3 - Divide and Conquer
PDF
DS & Algo 2 - Offline Assignment 2
PDF
DS & Algo 2 - Recursion
PDF
DS & Algo 1 - Offline Assignment 1
PDF
DS & Algo 1 - C++ and STL Introduction
PDF
DBMS 1 | Introduction to DBMS
PDF
DBMS 10 | Database Transactions
PDF
DBMS 3 | ER Diagram to Relational Schema
PDF
DBMS 2 | Entity Relationship Model
PDF
DBMS 7 | Relational Query Language
PDF
DBMS 4 | MySQL - DDL & DML Commands
PDF
DBMS 5 | MySQL Practice List - HR Schema
PDF
TOC 10 | Turing Machine
PDF
TOC 9 | Pushdown Automata
PDF
TOC 8 | Derivation, Parse Tree & Ambiguity Check
DS & Algo 6 - Offline Assignment 6
DS & Algo 6 - Dynamic Programming
DS & Algo 5 - Disjoint Set and MST
DS & Algo 4 - Graph and Shortest Path Search
DS & Algo 3 - Offline Assignment 3
DS & Algo 3 - Divide and Conquer
DS & Algo 2 - Offline Assignment 2
DS & Algo 2 - Recursion
DS & Algo 1 - Offline Assignment 1
DS & Algo 1 - C++ and STL Introduction
DBMS 1 | Introduction to DBMS
DBMS 10 | Database Transactions
DBMS 3 | ER Diagram to Relational Schema
DBMS 2 | Entity Relationship Model
DBMS 7 | Relational Query Language
DBMS 4 | MySQL - DDL & DML Commands
DBMS 5 | MySQL Practice List - HR Schema
TOC 10 | Turing Machine
TOC 9 | Pushdown Automata
TOC 8 | Derivation, Parse Tree & Ambiguity Check

Recently uploaded (20)

PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PDF
Computing-Curriculum for Schools in Ghana
PDF
VCE English Exam - Section C Student Revision Booklet
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PPTX
master seminar digital applications in india
PDF
Microbial disease of the cardiovascular and lymphatic systems
PPTX
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
PPTX
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PDF
Anesthesia in Laparoscopic Surgery in India
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PDF
Complications of Minimal Access Surgery at WLH
PDF
01-Introduction-to-Information-Management.pdf
Abdominal Access Techniques with Prof. Dr. R K Mishra
2.FourierTransform-ShortQuestionswithAnswers.pdf
Supply Chain Operations Speaking Notes -ICLT Program
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
Microbial diseases, their pathogenesis and prophylaxis
Computing-Curriculum for Schools in Ghana
VCE English Exam - Section C Student Revision Booklet
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
human mycosis Human fungal infections are called human mycosis..pptx
master seminar digital applications in india
Microbial disease of the cardiovascular and lymphatic systems
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
Pharmacology of Heart Failure /Pharmacotherapy of CHF
Anesthesia in Laparoscopic Surgery in India
FourierSeries-QuestionsWithAnswers(Part-A).pdf
Complications of Minimal Access Surgery at WLH
01-Introduction-to-Information-Management.pdf

SPL 12 | Multi-dimensional Array in C

  • 1. Structured Programming Language 2 Dimensional Array Mohammad Imam Hossain, Lecturer, CSE, UIU
  • 2. Array • A data structure that can store a fixed- size sequential collection of elements of same type. • More useful to think as a collection of variables of the same type. • Arrays we have consider up to now are one dimensional arrays, a single line of elements.
  • 3. Programming Language Rating 90 85 85 90 80 20 20 95 90 85 80 90 30 10 C C++ C# java python ruby perl Columns representing programming languages Differentpersons
  • 4. Why 2 D • Matrix calculator • Any kind of board game (chess, tic-tac-toe, number puzzle, word puzzle, minesweeper etc.) • Graph representation • Image representation • Excel data • Database table to store information etc………
  • 5. Declaration int x ; ///declaring integer type variable x
  • 6. Declaration int x ; ///declaring integer type variable x int x[100] ; ///declaring 1D array of 100 integers
  • 7. Declaration int x ; ///declaring integer type variable x int x[100] ; ///declaring 1D array of 100 integers int x[100] [50] ; ///declaring 100 1D array each of 50 integers ///i.e. a 2D array of 100 rows and 50 columns
  • 8. Declaration int x ; ///declaring integer type variable x int x[100] ; ///declaring 1D array of 100 integers int x[100] [50] ; ///declaring 100 1D array each of 50 integers ///i.e. a 2D array of 100 rows and 50 columns datatype arrayName [Max_rows][Max_cols] ; • datatype = any valid C data type. • arrayName = any valid C identifier.
  • 9. 2 D Array int a[Max_rows] [Max_cols] ; a[0][0] a[0][1] a[0][2] a[0][3] a[1][0] a[1][1] a[1][2] a[1][3] a[2][0] a[2][1] a[2][2] a[2][3] Col 0 Col 1 Col 2 Col 3 Max_cols-1 Row 0 Row 1 Row 2 Max_rows-1
  • 10. Initialization int arr[3][4]={1 , 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}; int arr[3][4]={ {1,2,3,4}, {5,6,7,8}, {9,10,11,12} }; Or, 1 2 3 4 5 6 7 8 9 10 11 12
  • 11. Accessing 2D array 1 2 3 4 5 6 7 8 9 10 11 12 Row 1 >>> Col 1 int var=arr[1][1]; /// the value of variable var is 6
  • 12. Accessing 2D array 1 2 3 4 5 6 7 8 9 10 11 12 Row 1 >>> Col 1 int var=arr[1][1]; /// the value of variable var is 6 scanf("%d",&arr[2][3]); /// let, input is 100 printf("%d",arr[2][3]); 100
  • 13. Accessing 2D array 1 2 3 4 5 6 7 8 9 10 11 12 Row 1 >>> Col 1 int var=arr[1][1]; /// the value of variable var is 6 scanf("%d",&arr[2][3]); /// let, input is 100 arr[0][0] = 20 ; printf("%d",arr[2][3]); 100 20
  • 14. Taking Input #include <stdio.h> #define ROW 5 #define COL 3 int main() { int arr[ROW][COL]; int r,c; for(r=0;r<ROW;r++){ for(c=0;c<COL;c++){ scanf("%d", &arr[r][c]); } } printf("Completedn"); ///other codes...... return 0; }
  • 15. Showing 2D array int r,c; for(r=0;r<ROW;r++){ for(c=0;c<COL;c++){ printf("%d ",arr[r][c]); } printf("n"); ///showing the next row in a different line }