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.
Multidimensional array in C
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

PPTX
uses of leflace transformation in the field of civil engineering by Engr mesb...
PPTX
Two dimensional arrays
PPTX
PPTX
Laplace transform
PPTX
Statistics "Descriptive & Inferential"
PPT
Solar power plant
PPTX
Solar energy(Renewable source)
PPTX
Arrays in Data Structure and Algorithm
uses of leflace transformation in the field of civil engineering by Engr mesb...
Two dimensional arrays
Laplace transform
Statistics "Descriptive & Inferential"
Solar power plant
Solar energy(Renewable source)
Arrays in Data Structure and Algorithm

What's hot (20)

PPTX
Programming in c Arrays
PPTX
Array Introduction One-dimensional array Multidimensional array
PPTX
Array ppt
PPT
C++ Arrays
PPTX
Presentation on array
PPTX
Arrays in c
PPTX
Nested loops
PPT
One Dimensional Array
PPTX
Function in C program
PPTX
Java Data Types
PPT
File handling in c
PDF
Character Array and String
PPTX
Python dictionary
PPTX
Strings in C language
PDF
Lesson 02 python keywords and identifiers
PPT
Strings
PPTX
2D Array
PPTX
Basics of Object Oriented Programming in Python
PPTX
PPTX
Data types in c++
Programming in c Arrays
Array Introduction One-dimensional array Multidimensional array
Array ppt
C++ Arrays
Presentation on array
Arrays in c
Nested loops
One Dimensional Array
Function in C program
Java Data Types
File handling in c
Character Array and String
Python dictionary
Strings in C language
Lesson 02 python keywords and identifiers
Strings
2D Array
Basics of Object Oriented Programming in Python
Data types in c++
Ad

Similar to Multidimensional array in C (20)

PPTX
Unit 3
PPTX
Array,MULTI ARRAY, IN C
PDF
CP Handout#9
PDF
C Language Lecture 10
PDF
C Language Lecture 11
PPT
Arrays in c programing. practicals and .ppt
PPT
Ch5 array nota
PPT
PPTX
C (PPS)Programming for problem solving.pptx
PDF
Programming Fundamentals Arrays and Strings
PPT
SP-First-Lecture.ppt
PPT
arrays
PPTX
Ch-11-Arrays.ppt-1.pptx eurhrbdhdbdhrhdhdh
PPT
array2d.ppt
PPTX
Two Dimentional Array
PPTX
Unit 3
PPT
DSA Lec-2 Arrays ADT FOR THE STUDENTS OF BSCS
PPTX
System Verilog Introduction with basics1
PPTX
Arrays 2d Arrays 2d Arrays 2d Arrrays 2d
PPTX
array.pptx ppt ggsipu bpit delhi rohini.
Unit 3
Array,MULTI ARRAY, IN C
CP Handout#9
C Language Lecture 10
C Language Lecture 11
Arrays in c programing. practicals and .ppt
Ch5 array nota
C (PPS)Programming for problem solving.pptx
Programming Fundamentals Arrays and Strings
SP-First-Lecture.ppt
arrays
Ch-11-Arrays.ppt-1.pptx eurhrbdhdbdhrhdhdh
array2d.ppt
Two Dimentional Array
Unit 3
DSA Lec-2 Arrays ADT FOR THE STUDENTS OF BSCS
System Verilog Introduction with basics1
Arrays 2d Arrays 2d Arrays 2d Arrrays 2d
array.pptx ppt ggsipu bpit delhi rohini.
Ad

Recently uploaded (20)

PPTX
Software-Development-Life-Cycle-SDLC.pptx
PDF
IAE-V2500 Engine for Airbus Family 319/320
PDF
ST MNCWANGO P2 WIL (MEPR302) FINAL REPORT.pdf
PPTX
22ME926Introduction to Business Intelligence and Analytics, Advanced Integrat...
PDF
ASPEN PLUS USER GUIDE - PROCESS SIMULATIONS
PDF
1.-fincantieri-investor-presentation2.pdf
PPTX
highway-150803160405-lva1-app6891 (1).pptx
PPTX
ARCHITECTURE AND PROGRAMMING OF EMBEDDED SYSTEMS
PPTX
INTERNET OF THINGS - EMBEDDED SYSTEMS AND INTERNET OF THINGS
PPTX
MODULE 3 SUSTAINABLE DEVELOPMENT GOALSPPT.pptx
PPTX
L1111-Important Microbial Mechanisms.pptx
PDF
IAE-V2500 Engine Airbus Family A319/320
PPTX
Unit IILATHEACCESSORSANDATTACHMENTS.pptx
PDF
PhD defense presentation in field of Computer Science
PDF
Introduction to Machine Learning -Basic concepts,Models and Description
PDF
ITEC 1010 - Networks and Cloud Computing
PPTX
MODULE 02 - CLOUD COMPUTING-Virtual Machines and Virtualization of Clusters a...
PPT
Module_1_Lecture_1_Introduction_To_Automation_In_Production_Systems2023.ppt
PDF
Performance, energy consumption and costs: a comparative analysis of automati...
PDF
V2500 Owner and Operatore Guide for Airbus
Software-Development-Life-Cycle-SDLC.pptx
IAE-V2500 Engine for Airbus Family 319/320
ST MNCWANGO P2 WIL (MEPR302) FINAL REPORT.pdf
22ME926Introduction to Business Intelligence and Analytics, Advanced Integrat...
ASPEN PLUS USER GUIDE - PROCESS SIMULATIONS
1.-fincantieri-investor-presentation2.pdf
highway-150803160405-lva1-app6891 (1).pptx
ARCHITECTURE AND PROGRAMMING OF EMBEDDED SYSTEMS
INTERNET OF THINGS - EMBEDDED SYSTEMS AND INTERNET OF THINGS
MODULE 3 SUSTAINABLE DEVELOPMENT GOALSPPT.pptx
L1111-Important Microbial Mechanisms.pptx
IAE-V2500 Engine Airbus Family A319/320
Unit IILATHEACCESSORSANDATTACHMENTS.pptx
PhD defense presentation in field of Computer Science
Introduction to Machine Learning -Basic concepts,Models and Description
ITEC 1010 - Networks and Cloud Computing
MODULE 02 - CLOUD COMPUTING-Virtual Machines and Virtualization of Clusters a...
Module_1_Lecture_1_Introduction_To_Automation_In_Production_Systems2023.ppt
Performance, energy consumption and costs: a comparative analysis of automati...
V2500 Owner and Operatore Guide for Airbus

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.
  • 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