Initializing the Matrices
- Declare two 3x3 matrices,
mat1
and mat2
.
- Ask the user to input the elements of the matrix using
cout
and cin
.
- Display the original matrix
mat1
using cout
.
#include <iostream>
using namespace std;
int main()
{
// Initializing matrices
int mat1[3][3], mat2[3][3];
int i, j;
// Getting elements input by user
cout << "Enter the elements of Matrix (3x3): " << endl;
for (i = 0; i < 3; i++) {
for (j = 0; j < 3; j++) {
cin >> mat1[i][j];
}
}
// Displaying the original matrix
cout << "\nMatrix is: " << endl;
for (i = 0; i < 3; i++) {
for (j = 0; j < 3; j++) {
cout << mat1[i][j] << " ";
}
cout << endl;
}
return 0;
}