Professional Documents
Culture Documents
Arrays
Prepared By Dalton Ndirangu
6.4 Two-dimensional Arrays
Arrays can have more than one dimension. In this section we briefly examine
the use of two-dimensional arrays to represent two-dimensional structures
such as nxm matrices of integers.
Pictorial interpretation
Example: Adding matrices
#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
int mat1[10][10];
int mat2[10][10];
int mat3[10][10];
int m,n;
int i,j;
mat1[m][n];
mat2[m][n];
mat3[m][n];
system("pause");
return 0;
}
Example2: Multiplying matrices of two
varying dimensions
#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
int mat1[10][10];
int mat2[10][10];
int mat3[10][10];
int m,n,p,q;
int i,j,k;
mat1[m][n];
p=n;
mat2[p][q];
mat3[m][q];
//multiply now
system("pause");
return 0;
}