SlideShare une entreprise Scribd logo
1  sur  9
TWO-DIMENSIONAL ARRAYS
TWO-DIMENSIONAL ARRAYS 
C++ also allows an array to have more than one dimension. 
For example, a two-dimensional array consists of a certain number of rows 
and columns: 
const int NUMROWS = 3; 
const int NUMCOLS = 7; 
int Array[NUMROWS][NUMCOLS]; 
0 1 2 3 4 5 6 
0 4 18 9 3 -4 6 0 
1 12 45 74 15 0 98 0 
2 84 87 75 67 81 85 79 
Array[2][5] 3rd value in 6th column 
Array[0][4] 1st value in 5th column 
The declaration must specify the number of rows and the number of columns, 
and both must be constants.
PROCESSING A 2-D ARRAY 
A one-dimensional array is usually processed via a for loop. Similarly, a two-dimensional 
array may be processed with a nested for loop: 
for (int Row = 0; Row < NUMROWS; Row++) { 
for (int Col = 0; Col < NUMCOLS; Col++) { 
Array[Row][Col] = 0; 
} 
} 
Each pass through the inner for loop will initialize all the elements of the current 
row to 0. 
The outer for loop drives the inner loop to process each of the array's rows.
INITIALIZING IN DECLARATIONS 
int Array1[2][3] = { {1, 2, 3} , {4, 5, 6} }; 
int Array2[2][3] = { 1, 2, 3, 4, 5 }; 
int Array3[2][3] = { {1, 2} , {4 } }; 
If we printed these arrays by rows, we would find the following initializations 
had taken place: 
Rows of Array1: 
1 2 3 
4 5 6 
Rows of Array2: 
1 2 3 
4 5 0 
Rows of Array3: 
1 2 0 
4 0 0 
for (int row = 0; row < 2; row++) { 
for (int col = 0; col < 3; col++) { 
cout << setw(3) 
<< Array1[row][col]; 
} 
cout << endl; 
}
EXAMPLE: INPUT USING CIN 
 Nested for loops are often used when 
inputting and assigning values to a two-dimensional array. 
 Nested loops are generally useful for getting around the 2D 
arrays… 
for (int i=0; i<RSIZE; ++i) //every row 
for (int j=0; j<CSIZE; ++j )//every col 
cin >> table[i][j];
2-D ARRAYS AS PARAMETERS 
When passing a two-dimensional array as a parameter, the base address is 
passed, as is the case with one-dimensional arrays. 
But now the number of columns in the array parameter must be specified. 
This is because arrays are stored in row-major order, and the number of 
columns must be known in order to calculate the location at which each row 
begins in memory: 
address of element (r, c) = base address of array 
+ r*(number of elements in a row)*(size of an 
element) 
+ c*(size of an element) 
void Initialize(int TwoD[][NUMCOLS], const int NUMROWS) { 
for (int i = 0; i < NUMROWS; i++) { 
for (int j = 0; j < NUMCOLS; j++) 
TwoD[i][j] = -1; 
} 
}
FUNCTION TO DISPLAY CONTENT OF A TWO 
DIMENSIONAL ARRAY A 
#include <iostream> 
#include <iomanip> 
using namespace std; 
void print(int A[][3],int N, int M) 
{ 
for (int R = 0; R < N; R++){ 
cout <<endl; 
for (int C = 0; C < M; C++) 
cout << setw(10) <<A[R][C]; 
} 
}
FUNCTION TO FIND THE SUM OF TWO DIMENSIONAL 
ARRAYS A AND B 
void addition(int A[][3], int B[][3],int N, int M) 
{ 
for(int R=0;R<N;R++){ 
cout<<endl; 
for(int C=0;C<M;C++) 
cout<<setw(10) <<A[R][C]+B[R][C]; 
} 
}
FUNCTION TO FIND & DISPLAY SUM OF ROWS & SUM 
OF COLS. OF A 2D ARRAY A 
void SumRowCol(int A[][20], int N, int M) 
{ 
for(int R=0;R<N;R++) 
{ 
int SumR=0; 
for(int C=0;C<M;C++) 
SumR+=A[R][C]; 
cout<<"Row("<<R<<")="<<SumR<<endl; 
} 
} 
for(int R=0;R<M;R++) 
{ 
int SumC=0; 
for(int C=0;C<N;C++) 
SumC+=A[C][R]; 
cout<<"Column("<<R<<")="<<SumC<<endl; 
} 
}

Contenu connexe

Tendances (20)

Array ppt
Array pptArray ppt
Array ppt
 
ARRAY
ARRAYARRAY
ARRAY
 
Array in C
Array in CArray in C
Array in C
 
Arrays in c
Arrays in cArrays in c
Arrays in c
 
C++ string
C++ stringC++ string
C++ string
 
One Dimensional Array
One Dimensional Array One Dimensional Array
One Dimensional Array
 
UNIT I LINEAR DATA STRUCTURES – LIST
UNIT I 	LINEAR DATA STRUCTURES – LIST 	UNIT I 	LINEAR DATA STRUCTURES – LIST
UNIT I LINEAR DATA STRUCTURES – LIST
 
Arrays in c language
Arrays in c languageArrays in c language
Arrays in c language
 
concept of Array, 1D & 2D array
concept of Array, 1D & 2D arrayconcept of Array, 1D & 2D array
concept of Array, 1D & 2D array
 
Strings in C
Strings in CStrings in C
Strings in C
 
Structure in c language
Structure in c languageStructure in c language
Structure in c language
 
Array Introduction One-dimensional array Multidimensional array
Array Introduction One-dimensional array Multidimensional arrayArray Introduction One-dimensional array Multidimensional array
Array Introduction One-dimensional array Multidimensional array
 
Arrays
ArraysArrays
Arrays
 
Java arrays
Java arraysJava arrays
Java arrays
 
Data Types - Premetive and Non Premetive
Data Types - Premetive and Non Premetive Data Types - Premetive and Non Premetive
Data Types - Premetive and Non Premetive
 
Arrays
ArraysArrays
Arrays
 
Pointers
PointersPointers
Pointers
 
Array in c++
Array in c++Array in c++
Array in c++
 
Data types in python
Data types in pythonData types in python
Data types in python
 
Strings in C language
Strings in C languageStrings in C language
Strings in C language
 

Similaire à 2- Dimensional Arrays

Similaire à 2- Dimensional Arrays (20)

Chapter13 two-dimensional-array
Chapter13 two-dimensional-arrayChapter13 two-dimensional-array
Chapter13 two-dimensional-array
 
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
 
Fp201 unit4
Fp201 unit4Fp201 unit4
Fp201 unit4
 
Array 31.8.2020 updated
Array 31.8.2020 updatedArray 31.8.2020 updated
Array 31.8.2020 updated
 
Chap 6 c++
Chap 6 c++Chap 6 c++
Chap 6 c++
 
Chap 6 c++
Chap 6 c++Chap 6 c++
Chap 6 c++
 
Arrays in C++
Arrays in C++Arrays in C++
Arrays in C++
 
Arrays & Strings.pptx
Arrays & Strings.pptxArrays & Strings.pptx
Arrays & Strings.pptx
 
Chapter 13.pptx
Chapter 13.pptxChapter 13.pptx
Chapter 13.pptx
 
Structured data type
Structured data typeStructured data type
Structured data type
 
Arrays and library functions
Arrays and library functionsArrays and library functions
Arrays and library functions
 
ARRAYS
ARRAYSARRAYS
ARRAYS
 
Computer Programming- Lecture 9
Computer Programming- Lecture 9Computer Programming- Lecture 9
Computer Programming- Lecture 9
 
Introduction to Arrays in C
Introduction to Arrays in CIntroduction to Arrays in C
Introduction to Arrays in C
 
Qno 3 (a)
Qno 3 (a)Qno 3 (a)
Qno 3 (a)
 
Arrays and strings in c++
Arrays and strings in c++Arrays and strings in c++
Arrays and strings in c++
 
19-Lec - Multidimensional Arrays.ppt
19-Lec - Multidimensional Arrays.ppt19-Lec - Multidimensional Arrays.ppt
19-Lec - Multidimensional Arrays.ppt
 
Multi dimensional arrays
Multi dimensional arraysMulti dimensional arrays
Multi dimensional arrays
 
Unit 2
Unit 2Unit 2
Unit 2
 
Array,MULTI ARRAY, IN C
Array,MULTI ARRAY, IN CArray,MULTI ARRAY, IN C
Array,MULTI ARRAY, IN C
 

Plus de Education Front

Plus de Education Front (20)

Improving Pronunciation
Improving PronunciationImproving Pronunciation
Improving Pronunciation
 
Generic Software Process Models
Generic Software Process ModelsGeneric Software Process Models
Generic Software Process Models
 
Problem Sloving
Problem SlovingProblem Sloving
Problem Sloving
 
Problem Solving - 1
Problem Solving - 1Problem Solving - 1
Problem Solving - 1
 
Introduction To Stack
Introduction To StackIntroduction To Stack
Introduction To Stack
 
Process Models
Process ModelsProcess Models
Process Models
 
Process Models
Process ModelsProcess Models
Process Models
 
Data Representation
Data RepresentationData Representation
Data Representation
 
Introduction to Algorithm
Introduction to AlgorithmIntroduction to Algorithm
Introduction to Algorithm
 
Revised Process of Communication
Revised Process of CommunicationRevised Process of Communication
Revised Process of Communication
 
Importance of Language in Communication
Importance of Language in CommunicationImportance of Language in Communication
Importance of Language in Communication
 
Lecture1 (SE Introduction)
Lecture1 (SE Introduction)Lecture1 (SE Introduction)
Lecture1 (SE Introduction)
 
Lecture 2 (Software Processes)
Lecture 2 (Software Processes)Lecture 2 (Software Processes)
Lecture 2 (Software Processes)
 
Introduction to data structure
Introduction to data structureIntroduction to data structure
Introduction to data structure
 
Facing Today’s Communication Challenges
Facing Today’s Communication ChallengesFacing Today’s Communication Challenges
Facing Today’s Communication Challenges
 
Processor Basics
Processor BasicsProcessor Basics
Processor Basics
 
Register & Memory
Register & MemoryRegister & Memory
Register & Memory
 
Data Representation
Data RepresentationData Representation
Data Representation
 
Computer Evolution
Computer EvolutionComputer Evolution
Computer Evolution
 
Assembly Language Basics
Assembly Language BasicsAssembly Language Basics
Assembly Language Basics
 

Dernier

Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxupamatechverse
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...Call Girls in Nagpur High Profile
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxAsutosh Ranjan
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Christo Ananth
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxupamatechverse
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Dr.Costas Sachpazis
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxupamatechverse
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escortsranjana rawat
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...ranjana rawat
 
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINESIVASHANKAR N
 
AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdfankushspencer015
 
MANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTING
MANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTINGMANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTING
MANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTINGSIVASHANKAR N
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)simmis5
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlysanyuktamishra911
 
Glass Ceramics: Processing and Properties
Glass Ceramics: Processing and PropertiesGlass Ceramics: Processing and Properties
Glass Ceramics: Processing and PropertiesPrabhanshu Chaturvedi
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxpranjaldaimarysona
 

Dernier (20)

Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptx
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptx
 
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptx
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptx
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
 
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
 
AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdf
 
MANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTING
MANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTINGMANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTING
MANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTING
 
Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghly
 
Glass Ceramics: Processing and Properties
Glass Ceramics: Processing and PropertiesGlass Ceramics: Processing and Properties
Glass Ceramics: Processing and Properties
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptx
 

2- Dimensional Arrays

  • 2. TWO-DIMENSIONAL ARRAYS C++ also allows an array to have more than one dimension. For example, a two-dimensional array consists of a certain number of rows and columns: const int NUMROWS = 3; const int NUMCOLS = 7; int Array[NUMROWS][NUMCOLS]; 0 1 2 3 4 5 6 0 4 18 9 3 -4 6 0 1 12 45 74 15 0 98 0 2 84 87 75 67 81 85 79 Array[2][5] 3rd value in 6th column Array[0][4] 1st value in 5th column The declaration must specify the number of rows and the number of columns, and both must be constants.
  • 3. PROCESSING A 2-D ARRAY A one-dimensional array is usually processed via a for loop. Similarly, a two-dimensional array may be processed with a nested for loop: for (int Row = 0; Row < NUMROWS; Row++) { for (int Col = 0; Col < NUMCOLS; Col++) { Array[Row][Col] = 0; } } Each pass through the inner for loop will initialize all the elements of the current row to 0. The outer for loop drives the inner loop to process each of the array's rows.
  • 4. INITIALIZING IN DECLARATIONS int Array1[2][3] = { {1, 2, 3} , {4, 5, 6} }; int Array2[2][3] = { 1, 2, 3, 4, 5 }; int Array3[2][3] = { {1, 2} , {4 } }; If we printed these arrays by rows, we would find the following initializations had taken place: Rows of Array1: 1 2 3 4 5 6 Rows of Array2: 1 2 3 4 5 0 Rows of Array3: 1 2 0 4 0 0 for (int row = 0; row < 2; row++) { for (int col = 0; col < 3; col++) { cout << setw(3) << Array1[row][col]; } cout << endl; }
  • 5. EXAMPLE: INPUT USING CIN  Nested for loops are often used when inputting and assigning values to a two-dimensional array.  Nested loops are generally useful for getting around the 2D arrays… for (int i=0; i<RSIZE; ++i) //every row for (int j=0; j<CSIZE; ++j )//every col cin >> table[i][j];
  • 6. 2-D ARRAYS AS PARAMETERS When passing a two-dimensional array as a parameter, the base address is passed, as is the case with one-dimensional arrays. But now the number of columns in the array parameter must be specified. This is because arrays are stored in row-major order, and the number of columns must be known in order to calculate the location at which each row begins in memory: address of element (r, c) = base address of array + r*(number of elements in a row)*(size of an element) + c*(size of an element) void Initialize(int TwoD[][NUMCOLS], const int NUMROWS) { for (int i = 0; i < NUMROWS; i++) { for (int j = 0; j < NUMCOLS; j++) TwoD[i][j] = -1; } }
  • 7. FUNCTION TO DISPLAY CONTENT OF A TWO DIMENSIONAL ARRAY A #include <iostream> #include <iomanip> using namespace std; void print(int A[][3],int N, int M) { for (int R = 0; R < N; R++){ cout <<endl; for (int C = 0; C < M; C++) cout << setw(10) <<A[R][C]; } }
  • 8. FUNCTION TO FIND THE SUM OF TWO DIMENSIONAL ARRAYS A AND B void addition(int A[][3], int B[][3],int N, int M) { for(int R=0;R<N;R++){ cout<<endl; for(int C=0;C<M;C++) cout<<setw(10) <<A[R][C]+B[R][C]; } }
  • 9. FUNCTION TO FIND & DISPLAY SUM OF ROWS & SUM OF COLS. OF A 2D ARRAY A void SumRowCol(int A[][20], int N, int M) { for(int R=0;R<N;R++) { int SumR=0; for(int C=0;C<M;C++) SumR+=A[R][C]; cout<<"Row("<<R<<")="<<SumR<<endl; } } for(int R=0;R<M;R++) { int SumC=0; for(int C=0;C<N;C++) SumC+=A[C][R]; cout<<"Column("<<R<<")="<<SumC<<endl; } }