SlideShare a Scribd company logo
1 of 15
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

What's hot (20)

Multidimensional array in C
Multidimensional array in CMultidimensional array in C
Multidimensional array in C
 
Introduction to Array ppt
Introduction to Array pptIntroduction to Array ppt
Introduction to Array ppt
 
Arrays in c
Arrays in cArrays in c
Arrays in c
 
Lecture17 arrays.ppt
Lecture17 arrays.pptLecture17 arrays.ppt
Lecture17 arrays.ppt
 
Arrays in c language
Arrays in c languageArrays in c language
Arrays in c language
 
Arrays In C
Arrays In CArrays In C
Arrays In C
 
Array in C
Array in CArray in C
Array in C
 
Day 2b i/o.pptx
Day 2b   i/o.pptxDay 2b   i/o.pptx
Day 2b i/o.pptx
 
Lecture 15 - Array
Lecture 15 - ArrayLecture 15 - Array
Lecture 15 - Array
 
Array
ArrayArray
Array
 
Array in c++
Array in c++Array in c++
Array in c++
 
One dimensional 2
One dimensional 2One dimensional 2
One dimensional 2
 
Array in c
Array in cArray in c
Array in c
 
Day 2 repeats.pptx
Day 2 repeats.pptxDay 2 repeats.pptx
Day 2 repeats.pptx
 
Presentation about arrays
Presentation about arraysPresentation about arrays
Presentation about arrays
 
concept of Array, 1D & 2D array
concept of Array, 1D & 2D arrayconcept of Array, 1D & 2D array
concept of Array, 1D & 2D array
 
Two dimensional arrays
Two dimensional arraysTwo dimensional arrays
Two dimensional arrays
 
Two dimensional array
Two dimensional arrayTwo dimensional array
Two dimensional array
 
C++ lecture 04
C++ lecture 04C++ lecture 04
C++ lecture 04
 
Arrays basics
Arrays basicsArrays basics
Arrays basics
 

Similar to SPL 12 | Multi-dimensional Array in C

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

Language R
Language RLanguage R
Language R
 
Numpy.pdf
Numpy.pdfNumpy.pdf
Numpy.pdf
 
C (PPS)Programming for problem solving.pptx
C (PPS)Programming for problem solving.pptxC (PPS)Programming for problem solving.pptx
C (PPS)Programming for problem solving.pptx
 
Arrays and library functions
Arrays and library functionsArrays and library functions
Arrays and library functions
 
Arrays & Strings.pptx
Arrays & Strings.pptxArrays & Strings.pptx
Arrays & Strings.pptx
 
Arrays
ArraysArrays
Arrays
 
C++ Arrays
C++ ArraysC++ Arrays
C++ Arrays
 
C++ Arrays
C++ ArraysC++ Arrays
C++ Arrays
 
C Language Lecture 10
C Language Lecture 10C Language Lecture 10
C Language Lecture 10
 
Arrays
ArraysArrays
Arrays
 
R Programming.pptx
R Programming.pptxR Programming.pptx
R Programming.pptx
 
Session 4
Session 4Session 4
Session 4
 
SPL 10 | One Dimensional Array in C
SPL 10 | One Dimensional Array in CSPL 10 | One Dimensional Array in C
SPL 10 | One Dimensional Array in C
 
Multi dimensional arrays
Multi dimensional arraysMulti dimensional arrays
Multi dimensional arrays
 
6 arrays injava
6 arrays injava6 arrays injava
6 arrays injava
 
Arrays 1D and 2D , and multi dimensional
Arrays 1D and 2D , and multi dimensional Arrays 1D and 2D , and multi dimensional
Arrays 1D and 2D , and multi dimensional
 
Basics of Python
Basics of PythonBasics of Python
Basics of Python
 
C Language Lecture 11
C Language Lecture  11C Language Lecture  11
C Language Lecture 11
 
C data types, arrays and structs
C data types, arrays and structsC data types, arrays and structs
C data types, arrays and structs
 
Lec4
Lec4Lec4
Lec4
 

More from Mohammad Imam Hossain

DS & Algo 4 - Graph and Shortest Path Search
DS & Algo 4 - Graph and Shortest Path SearchDS & Algo 4 - Graph and Shortest Path Search
DS & Algo 4 - Graph and Shortest Path SearchMohammad Imam Hossain
 
DS & Algo 1 - C++ and STL Introduction
DS & Algo 1 - C++ and STL IntroductionDS & Algo 1 - C++ and STL Introduction
DS & Algo 1 - C++ and STL IntroductionMohammad Imam Hossain
 
DBMS 3 | ER Diagram to Relational Schema
DBMS 3 | ER Diagram to Relational SchemaDBMS 3 | ER Diagram to Relational Schema
DBMS 3 | ER Diagram to Relational SchemaMohammad Imam Hossain
 
DBMS 5 | MySQL Practice List - HR Schema
DBMS 5 | MySQL Practice List - HR SchemaDBMS 5 | MySQL Practice List - HR Schema
DBMS 5 | MySQL Practice List - HR SchemaMohammad Imam Hossain
 
TOC 8 | Derivation, Parse Tree & Ambiguity Check
TOC 8 | Derivation, Parse Tree & Ambiguity CheckTOC 8 | Derivation, Parse Tree & Ambiguity Check
TOC 8 | Derivation, Parse Tree & Ambiguity CheckMohammad Imam Hossain
 

More from Mohammad Imam Hossain (20)

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

Recently uploaded

How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17Celine George
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxJisc
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSCeline George
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxAreebaZafar22
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.christianmathematics
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17Celine George
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxEsquimalt MFRC
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxheathfieldcps1
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxDenish Jangid
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jisc
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structuredhanjurrannsibayan2
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024Elizabeth Walsh
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentationcamerronhm
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsKarakKing
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the ClassroomPooky Knightsmith
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...pradhanghanshyam7136
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...Nguyen Thanh Tu Collection
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibitjbellavia9
 

Recently uploaded (20)

How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 

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 }