Following C++ program ask to the user to enter any two 3*3 array elements to subtract them i.e., Matrix1 - Matrix2, then display the subtracted result of the two matrices (Matrix3) on the screen Test Case 1 Input (stdin) 8 6 2 9 5 6 8 2 7 6 5 4 6 7 8 9 3 9 Expected Output Result of Array1 - Array2 is : 2 1 -2 3 -2 -2 -1 -1 -2 Test Case 2 Input (stdin) 6 9 2 7 8 9 6 7 9 4 7 9 7 5 8 9 5 8 Expected Output Result of Array1 - Array2 is : 2 2 -7 0 3 1 -3 2 1
#include<iostream> using namespace std; int main() { int m1[3][3], m2[3][3], i, j, m3[3][3]; for(i=0; i<3; i++) { for(j=0; j<3; j++) cin>>m1[i][j]; } for(i=0; i<3; i++) { for(j=0; j<3; j++) cin>>m2[i][j]; } for(i=0; i<3; i++) { for(j=0; j<3; j++) m3[i][j]=m1[i][j]-m2[i][j]; } cout<<"Result of Array1 - Array2 is :\n"; for(i=0; i<3; i++) { for(j=0; j<3; j++) cout<<m3[i][j]<<" "; cout<<"\n"; } return 0; }