SlideShare a Scribd company logo
MULTI-DIMENSIONAL
ARRAY
By Smit Parikh
Multi-Dimensional Arrays
 Multidimensional arrays are derived from the
basic or built-in data types of the C language.
 Two-dimensional arrays are understood as rows
and columns with applications including two-
dimensional tables, parallel vectors, and two-
dimensional matrices.
 Mostly Two-dimensional array are used in
Multi-dimensional array.
Arrays of Greater
DimensionOne-dimensional arrays are linear containers.
Multi-dimensional Arrays
Two-Dimensional
Three-dimensional
[0] [1] [2]
[0] [1] [2] [3]
[0]
[1]
[2]
[0]
[0]
[1]
[1]
[2]
[2]
[3]
[0] [1] [2] [3] [4]
TWO DIMENSIONAL
ARRAY
CONTENT
 Introduction to two dimensional array
 Declaration
 Initialization
 Input and output of a 2d array
 Storage allocation
Two - Dimensional Arrays
 What is a Two-dimensional array?
B =
51, 52, 53
54, 55, 56
Algebraic notation
Col 1 Col 2 Col 3
Row 1
Row 2
Int b[2][3] = {(51, 52, 53),(54, 55, 56)};
Array type Array name
Array dimension = 2
Two rows
Three columns
First row second row
C notation
7
Indexes in 2D arrays
 Assume that the two dimensional array called val is
declared and looks like the following:
 To access the cell containing 6, we reference val[1]
[3], that is, row 1, column 3.
val Col 0 Col 1 Col 2 Col 3
Row 0 8 16 9 52
Row 1 3 15 27 6
Row 2 14 25 2 10
DECLARATION
 How to declare a multidimensional array?
int b[2][3];
the name of the array to be b
the type of the array elements to be int
the dimension to be 2 (two pairs of brackets [])
the number of elements or size to be 2*3 = 6
Declaration Statement
 How to initialize a Two-Dimensional array?
 Initialized directly in the declaration statement
 int b[2][3] = {51, 52, 53, 54, 55, 56};
 b[0][0] = 51 b[0][1] = 52 b[0][2] = 53
 Use braces to separate rows in 2-D arrays.
 int c[4][3] = {{1, 2, 3},
{4, 5, 6},
{7, 8, 9},
{10, 11, 12}};
 int c[ ][3] = {{1, 2, 3},
{4, 5, 6},
{7, 8, 9},
{10, 11, 12}};
Implicitly declares the number of rows to be 4.
INITIALIZATION
Input of Two-Dimensional Arrays
 Data may be input into two-dimensional
arrays using nested for loops interactively
or with data files.
 A nested for loop is used to input elemts in
a two dimensional array.
 In this way by increasing the index value of
the array the elements can be entered in a
2d array.
Output of Two-Dimensional Arrays
 The output of two-dimensional arrays should
be in the form of rows and columns for
readability. Nested for loops are used to print
the rows and columns in row and column
order.
 By increasing the index value of the array the
elements stored at that index value are printed
on the output screen.
A program to input elements in a
two dimensional array and print it.
#include<stdio.h>
#include<conio.h>
void main()
{
int a[3][3];
int i,j;
clrscr();
printf(“enter the elements in the array:”);
for(i=0 ; i<3 ; i++)
{
for(j=0 ; j<3 ; j++)
{
scanf(“%d”,&a[i][j]);
}
}
for(i=0 ; i<3 ; i++)
{
for(j=0 ; j<3 ; j++)
{
printf(“%d”,a[i][j]);
} printf(“n”);
}
getch();
}
OUTPUT :-
Enter elements in array:
1
2
3
4
5
6
7
8
9
123
456
789
Storage Allocation
In storage allocation of array contagious memory is
allocated to all the array elements.
EXAMPLES BASED ON
TWO-DIMENSIONAL
ARRAY
A program to add two matrix
entered by the user and print it.
#include<stdio.h>
#include<conio.h>
void main()
{
int a[3][3],b[3][3],c[3][3];
int i,j;
clrscr();
printf(“enter the elements in both the array:”);
for(i=0 ; i<3 ; i++)
{
for(j=0 ; j<3 ; j++)
{
scanf(“%d”,&a[i][j]);
}
}
for(i=0 ; i<3 ; i++)
{
for(j=0 ; j<3 ; j++)
{
scanf(“%d”,&b[i][j]);
}
}
for(i=0 ; i<3 ; i++)
{
for(j=0 ; j<3 ; j++)
{
c[i][j]=a[i][j]+b[i][j];
printf(“%d”,c[i][j]);
}
printf(“n”);
}
getch();
}
OUTPUT:-
Enter elements in array:-
1 3
2 4
3 5
4 6
5 7
6 8
7 9
8 2 4 6
9 81012
1 141618
2
A program to input a matrix and
print its transpose.
#include<stdio.h>
#include<conio.h>
void main()
{
int a[3][3],b[3][3];
int i,j;
clrscr();
printf(“enter the elements in the array”);
for(i=0 ; i<3 ; i++)
{
for(j=0 ; j<3 ; j++)
{
scanf(“%d”,&a[i][j]);
}
}
for(j=0 ; i<3 ; i++)
{
for(i=0 ; j<3 ; j++)
{
printf(“%2d”,&b[j][i]);
}
}
getch();
}
OUTPUT:-
Enter elements in array:
1
2
3
4
5
6
7
8
9
147
258
369
A program to multiply two matrix
entered by the user and print it.
#include<stdio.h>
#include<conio.h>
void main()
{
int a[3][3],b[3][3];
int i,j;
clrscr();
printf(“enter the elements in the array”);
for(i=0 ; i<3 ; i++)
{
for(j=0 ; j<3 ; j++)
{
scanf(“%d”,&a[i][j]);
}
}
for(i=0 ; i<3 ; i++)
{
for(j=0 ; j<3 ; j++)
{
scanf(“%d”,&b[i][j]);
}
}
for(i=0 ; i<3 ; i++)
{
for(j=0 ; j<3 ; j++)
c[i][j]=0;
{
for(k=0 ; k<2 ; k++)
{
c[i][j]=c[i][j]+a[i][k]*b[k][j]
printf(“%3d”,c[i][j]);
}
}
printf(“n”);
}
getch();
}
OUTPUT:-
Enter elements in array:-
1 3
2 4
3 5
4 6
5 7
6 8
7 9
8 30 66 102
9 36 81 121
1 42 96 150
2
THANK YOU

More Related Content

What's hot

Array in c
Array in cArray in c
Array in c
Ravi Gelani
 
Multi dimensional arrays
Multi dimensional arraysMulti dimensional arrays
Multi dimensional arraysAseelhalees
 
Arrays in c
Arrays in cArrays in c
Arrays in c
Jeeva Nanthini
 
Array in C
Array in CArray in C
Array in C
Kamal Acharya
 
Two dimensional arrays
Two dimensional arraysTwo dimensional arrays
Two dimensional arrays
Neeru Mittal
 
Strings in C
Strings in CStrings in C
Strings in C
Kamal Acharya
 
Two dimensional array
Two dimensional arrayTwo dimensional array
Two dimensional array
Rajendran
 
Programming in c Arrays
Programming in c ArraysProgramming in c Arrays
Programming in c Arrays
janani thirupathi
 
Conditional Statement in C Language
Conditional Statement in C LanguageConditional Statement in C Language
Conditional Statement in C Language
Shaina Arora
 
Dynamic memory allocation in c
Dynamic memory allocation in cDynamic memory allocation in c
Dynamic memory allocation in c
lavanya marichamy
 
Arrays in c
Arrays in cArrays in c
Arrays in c
vampugani
 
Array
ArrayArray
Array
PRN USM
 
Tuples in Python
Tuples in PythonTuples in Python
Tuples in Python
DPS Ranipur Haridwar UK
 
Pointer in c
Pointer in cPointer in c
Pointer in c
lavanya marichamy
 
C pointer
C pointerC pointer
Presentation on array
Presentation on array Presentation on array
Presentation on array
topu93
 
Arrays in c
Arrays in cArrays in c
Arrays in c
CHANDAN KUMAR
 
Array in c++
Array in c++Array in c++
Array in c++
Mahesha Mano
 

What's hot (20)

Array in c
Array in cArray in c
Array in c
 
Multi dimensional arrays
Multi dimensional arraysMulti dimensional arrays
Multi dimensional arrays
 
Arrays in c
Arrays in cArrays in c
Arrays in c
 
Array in C
Array in CArray in C
Array in C
 
Two dimensional arrays
Two dimensional arraysTwo dimensional arrays
Two dimensional arrays
 
Strings in C
Strings in CStrings in C
Strings in C
 
Two dimensional array
Two dimensional arrayTwo dimensional array
Two dimensional array
 
Programming in c Arrays
Programming in c ArraysProgramming in c Arrays
Programming in c Arrays
 
Conditional Statement in C Language
Conditional Statement in C LanguageConditional Statement in C Language
Conditional Statement in C Language
 
Dynamic memory allocation in c
Dynamic memory allocation in cDynamic memory allocation in c
Dynamic memory allocation in c
 
Arrays in c
Arrays in cArrays in c
Arrays in c
 
Array
ArrayArray
Array
 
Tuples in Python
Tuples in PythonTuples in Python
Tuples in Python
 
Arrays in Java
Arrays in JavaArrays in Java
Arrays in Java
 
Pointer in c
Pointer in cPointer in c
Pointer in c
 
C pointer
C pointerC pointer
C pointer
 
Presentation on array
Presentation on array Presentation on array
Presentation on array
 
Arrays in c
Arrays in cArrays in c
Arrays in c
 
Strings
StringsStrings
Strings
 
Array in c++
Array in c++Array in c++
Array in c++
 

Similar to Multidimensional array in C

Unit 3
Unit 3 Unit 3
Unit 3
GOWSIKRAJAP
 
Array,MULTI ARRAY, IN C
Array,MULTI ARRAY, IN CArray,MULTI ARRAY, IN C
Array,MULTI ARRAY, IN C
naveed jamali
 
CP Handout#9
CP Handout#9CP Handout#9
CP Handout#9
trupti1976
 
C Language Lecture 10
C Language Lecture 10C Language Lecture 10
C Language Lecture 10
Shahzaib Ajmal
 
C Language Lecture 11
C Language Lecture  11C Language Lecture  11
C Language Lecture 11
Shahzaib Ajmal
 
Arrays
ArraysArrays
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
rohinitalekar1
 
Programming Fundamentals Arrays and Strings
Programming Fundamentals   Arrays and Strings Programming Fundamentals   Arrays and Strings
Programming Fundamentals Arrays and Strings
imtiazalijoono
 
SP-First-Lecture.ppt
SP-First-Lecture.pptSP-First-Lecture.ppt
SP-First-Lecture.ppt
FareedIhsas
 
arrays
arraysarrays
arrays
teach4uin
 
Two Dimentional Array
Two Dimentional ArrayTwo Dimentional Array
Two Dimentional Array
Sonya Akter Rupa
 
Unit 3
Unit 3 Unit 3
Unit 3
GOWSIKRAJAP
 
array-191103180006.pdf
array-191103180006.pdfarray-191103180006.pdf
array-191103180006.pdf
HEMAHEMS5
 
Arrays
ArraysArrays
C Arrays.ppt
C Arrays.pptC Arrays.ppt
C Arrays.ppt
ssuser0c1819
 
Array in C full basic explanation
Array in C full basic explanationArray in C full basic explanation
Array in C full basic explanation
TeresaJencyBala
 
A quick introduction to R
A quick introduction to RA quick introduction to R
A quick introduction to R
Angshuman Saha
 
Chapter 13.pptx
Chapter 13.pptxChapter 13.pptx
Chapter 13.pptx
AnisZahirahAzman
 

Similar to Multidimensional array in C (20)

Unit 3
Unit 3 Unit 3
Unit 3
 
Array,MULTI ARRAY, IN C
Array,MULTI ARRAY, IN CArray,MULTI ARRAY, IN C
Array,MULTI ARRAY, IN C
 
CP Handout#9
CP Handout#9CP Handout#9
CP Handout#9
 
C Language Lecture 10
C Language Lecture 10C Language Lecture 10
C Language Lecture 10
 
C Language Lecture 11
C Language Lecture  11C Language Lecture  11
C Language Lecture 11
 
Ch5 array nota
Ch5 array notaCh5 array nota
Ch5 array nota
 
Arrays
ArraysArrays
Arrays
 
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
 
Programming Fundamentals Arrays and Strings
Programming Fundamentals   Arrays and Strings Programming Fundamentals   Arrays and Strings
Programming Fundamentals Arrays and Strings
 
SP-First-Lecture.ppt
SP-First-Lecture.pptSP-First-Lecture.ppt
SP-First-Lecture.ppt
 
arrays
arraysarrays
arrays
 
array2d.ppt
array2d.pptarray2d.ppt
array2d.ppt
 
Two Dimentional Array
Two Dimentional ArrayTwo Dimentional Array
Two Dimentional Array
 
Unit 3
Unit 3 Unit 3
Unit 3
 
array-191103180006.pdf
array-191103180006.pdfarray-191103180006.pdf
array-191103180006.pdf
 
Arrays
ArraysArrays
Arrays
 
C Arrays.ppt
C Arrays.pptC Arrays.ppt
C Arrays.ppt
 
Array in C full basic explanation
Array in C full basic explanationArray in C full basic explanation
Array in C full basic explanation
 
A quick introduction to R
A quick introduction to RA quick introduction to R
A quick introduction to R
 
Chapter 13.pptx
Chapter 13.pptxChapter 13.pptx
Chapter 13.pptx
 

Recently uploaded

The Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdfThe Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdf
Pipe Restoration Solutions
 
Student information management system project report ii.pdf
Student information management system project report ii.pdfStudent information management system project report ii.pdf
Student information management system project report ii.pdf
Kamal Acharya
 
H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
H.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdfH.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdf
H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
MLILAB
 
English lab ppt no titlespecENG PPTt.pdf
English lab ppt no titlespecENG PPTt.pdfEnglish lab ppt no titlespecENG PPTt.pdf
English lab ppt no titlespecENG PPTt.pdf
BrazilAccount1
 
block diagram and signal flow graph representation
block diagram and signal flow graph representationblock diagram and signal flow graph representation
block diagram and signal flow graph representation
Divya Somashekar
 
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdfTop 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Teleport Manpower Consultant
 
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&BDesign and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Sreedhar Chowdam
 
Final project report on grocery store management system..pdf
Final project report on grocery store management system..pdfFinal project report on grocery store management system..pdf
Final project report on grocery store management system..pdf
Kamal Acharya
 
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Dr.Costas Sachpazis
 
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdf
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdfGoverning Equations for Fundamental Aerodynamics_Anderson2010.pdf
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdf
WENKENLI1
 
weather web application report.pdf
weather web application report.pdfweather web application report.pdf
weather web application report.pdf
Pratik Pawar
 
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
Amil Baba Dawood bangali
 
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdfAKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
SamSarthak3
 
J.Yang, ICLR 2024, MLILAB, KAIST AI.pdf
J.Yang,  ICLR 2024, MLILAB, KAIST AI.pdfJ.Yang,  ICLR 2024, MLILAB, KAIST AI.pdf
J.Yang, ICLR 2024, MLILAB, KAIST AI.pdf
MLILAB
 
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
obonagu
 
DESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docxDESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docx
FluxPrime1
 
Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024
Massimo Talia
 
Fundamentals of Electric Drives and its applications.pptx
Fundamentals of Electric Drives and its applications.pptxFundamentals of Electric Drives and its applications.pptx
Fundamentals of Electric Drives and its applications.pptx
manasideore6
 
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
ydteq
 
WATER CRISIS and its solutions-pptx 1234
WATER CRISIS and its solutions-pptx 1234WATER CRISIS and its solutions-pptx 1234
WATER CRISIS and its solutions-pptx 1234
AafreenAbuthahir2
 

Recently uploaded (20)

The Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdfThe Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdf
 
Student information management system project report ii.pdf
Student information management system project report ii.pdfStudent information management system project report ii.pdf
Student information management system project report ii.pdf
 
H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
H.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdfH.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdf
H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
 
English lab ppt no titlespecENG PPTt.pdf
English lab ppt no titlespecENG PPTt.pdfEnglish lab ppt no titlespecENG PPTt.pdf
English lab ppt no titlespecENG PPTt.pdf
 
block diagram and signal flow graph representation
block diagram and signal flow graph representationblock diagram and signal flow graph representation
block diagram and signal flow graph representation
 
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdfTop 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
 
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&BDesign and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
 
Final project report on grocery store management system..pdf
Final project report on grocery store management system..pdfFinal project report on grocery store management system..pdf
Final project report on grocery store management system..pdf
 
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
 
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdf
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdfGoverning Equations for Fundamental Aerodynamics_Anderson2010.pdf
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdf
 
weather web application report.pdf
weather web application report.pdfweather web application report.pdf
weather web application report.pdf
 
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
 
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdfAKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
 
J.Yang, ICLR 2024, MLILAB, KAIST AI.pdf
J.Yang,  ICLR 2024, MLILAB, KAIST AI.pdfJ.Yang,  ICLR 2024, MLILAB, KAIST AI.pdf
J.Yang, ICLR 2024, MLILAB, KAIST AI.pdf
 
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
 
DESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docxDESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docx
 
Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024
 
Fundamentals of Electric Drives and its applications.pptx
Fundamentals of Electric Drives and its applications.pptxFundamentals of Electric Drives and its applications.pptx
Fundamentals of Electric Drives and its applications.pptx
 
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
 
WATER CRISIS and its solutions-pptx 1234
WATER CRISIS and its solutions-pptx 1234WATER CRISIS and its solutions-pptx 1234
WATER CRISIS and its solutions-pptx 1234
 

Multidimensional array in C

  • 2. Multi-Dimensional Arrays  Multidimensional arrays are derived from the basic or built-in data types of the C language.  Two-dimensional arrays are understood as rows and columns with applications including two- dimensional tables, parallel vectors, and two- dimensional matrices.  Mostly Two-dimensional array are used in Multi-dimensional array.
  • 3. Arrays of Greater DimensionOne-dimensional arrays are linear containers. Multi-dimensional Arrays Two-Dimensional Three-dimensional [0] [1] [2] [0] [1] [2] [3] [0] [1] [2] [0] [0] [1] [1] [2] [2] [3] [0] [1] [2] [3] [4]
  • 5. CONTENT  Introduction to two dimensional array  Declaration  Initialization  Input and output of a 2d array  Storage allocation
  • 6. Two - Dimensional Arrays  What is a Two-dimensional array? B = 51, 52, 53 54, 55, 56 Algebraic notation Col 1 Col 2 Col 3 Row 1 Row 2 Int b[2][3] = {(51, 52, 53),(54, 55, 56)}; Array type Array name Array dimension = 2 Two rows Three columns First row second row C notation
  • 7. 7 Indexes in 2D arrays  Assume that the two dimensional array called val is declared and looks like the following:  To access the cell containing 6, we reference val[1] [3], that is, row 1, column 3. val Col 0 Col 1 Col 2 Col 3 Row 0 8 16 9 52 Row 1 3 15 27 6 Row 2 14 25 2 10
  • 8. DECLARATION  How to declare a multidimensional array? int b[2][3]; the name of the array to be b the type of the array elements to be int the dimension to be 2 (two pairs of brackets []) the number of elements or size to be 2*3 = 6
  • 10.  How to initialize a Two-Dimensional array?  Initialized directly in the declaration statement  int b[2][3] = {51, 52, 53, 54, 55, 56};  b[0][0] = 51 b[0][1] = 52 b[0][2] = 53  Use braces to separate rows in 2-D arrays.  int c[4][3] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}, {10, 11, 12}};  int c[ ][3] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}, {10, 11, 12}}; Implicitly declares the number of rows to be 4. INITIALIZATION
  • 11. Input of Two-Dimensional Arrays  Data may be input into two-dimensional arrays using nested for loops interactively or with data files.  A nested for loop is used to input elemts in a two dimensional array.  In this way by increasing the index value of the array the elements can be entered in a 2d array.
  • 12. Output of Two-Dimensional Arrays  The output of two-dimensional arrays should be in the form of rows and columns for readability. Nested for loops are used to print the rows and columns in row and column order.  By increasing the index value of the array the elements stored at that index value are printed on the output screen.
  • 13. A program to input elements in a two dimensional array and print it. #include<stdio.h> #include<conio.h> void main() { int a[3][3]; int i,j; clrscr(); printf(“enter the elements in the array:”);
  • 14. for(i=0 ; i<3 ; i++) { for(j=0 ; j<3 ; j++) { scanf(“%d”,&a[i][j]); } } for(i=0 ; i<3 ; i++) { for(j=0 ; j<3 ; j++) { printf(“%d”,a[i][j]); } printf(“n”); } getch(); }
  • 15. OUTPUT :- Enter elements in array: 1 2 3 4 5 6 7 8 9 123 456 789
  • 16. Storage Allocation In storage allocation of array contagious memory is allocated to all the array elements.
  • 17.
  • 19. A program to add two matrix entered by the user and print it. #include<stdio.h> #include<conio.h> void main() { int a[3][3],b[3][3],c[3][3]; int i,j; clrscr(); printf(“enter the elements in both the array:”);
  • 20. for(i=0 ; i<3 ; i++) { for(j=0 ; j<3 ; j++) { scanf(“%d”,&a[i][j]); } } for(i=0 ; i<3 ; i++) { for(j=0 ; j<3 ; j++) { scanf(“%d”,&b[i][j]); } }
  • 21. for(i=0 ; i<3 ; i++) { for(j=0 ; j<3 ; j++) { c[i][j]=a[i][j]+b[i][j]; printf(“%d”,c[i][j]); } printf(“n”); } getch(); }
  • 22. OUTPUT:- Enter elements in array:- 1 3 2 4 3 5 4 6 5 7 6 8 7 9 8 2 4 6 9 81012 1 141618 2
  • 23. A program to input a matrix and print its transpose. #include<stdio.h> #include<conio.h> void main() { int a[3][3],b[3][3]; int i,j; clrscr(); printf(“enter the elements in the array”);
  • 24. for(i=0 ; i<3 ; i++) { for(j=0 ; j<3 ; j++) { scanf(“%d”,&a[i][j]); } } for(j=0 ; i<3 ; i++) { for(i=0 ; j<3 ; j++) { printf(“%2d”,&b[j][i]); } } getch(); }
  • 25. OUTPUT:- Enter elements in array: 1 2 3 4 5 6 7 8 9 147 258 369
  • 26. A program to multiply two matrix entered by the user and print it. #include<stdio.h> #include<conio.h> void main() { int a[3][3],b[3][3]; int i,j; clrscr(); printf(“enter the elements in the array”);
  • 27. for(i=0 ; i<3 ; i++) { for(j=0 ; j<3 ; j++) { scanf(“%d”,&a[i][j]); } } for(i=0 ; i<3 ; i++) { for(j=0 ; j<3 ; j++) { scanf(“%d”,&b[i][j]); } }
  • 28. for(i=0 ; i<3 ; i++) { for(j=0 ; j<3 ; j++) c[i][j]=0; { for(k=0 ; k<2 ; k++) { c[i][j]=c[i][j]+a[i][k]*b[k][j] printf(“%3d”,c[i][j]); } } printf(“n”); } getch(); }
  • 29. OUTPUT:- Enter elements in array:- 1 3 2 4 3 5 4 6 5 7 6 8 7 9 8 30 66 102 9 36 81 121 1 42 96 150 2