C++ Programming Code Examples C++ > Arrays and Matrices Code Examples Programming Code to Add Two Matrices Programming Code to Add Two Matrices To add two matrices in C++ Programming, you have to ask to the user to enter the elements of both the matrix, now start adding the two matrix to form a new matrix. After adding two matrices display the third matrix which is the result of the addition of the two matrices as shown in the following program. Following C++ program add two 3*3 matrices to form the third matrix : /* C++ Program - Add Two Matrices */ #include<iostream.h> #include<conio.h> void main() { clrscr(); int mat1[3][3], mat2[3][3], x, j, mat3[3][3]; cout<<"Enter matrix 1 elements :"; for(x=0; x<3; x++) { for(j=0; j<3; j++) { cin>>mat1[x][j]; } } cout<<"Enter matrix 2 elements :"; for(x=0; x<3; x++) { for(j=0; j<3; j++) { cin>>mat2[x][j]; } } cout<<"Adding the two matrix to form the third matrix .....\n"; for(x=0; x<3; x++) { for(j=0; j<3; j++) { mat3[x][j]=mat1[x][j]+mat2[x][j]; } } cout<<"The two matrix added successfully...!!"; cout<<"The new matrix will be :\n"; for(x=0; x<3; x++) { for(j=0; j<3; j++) { cout<<mat3[x][j]<<" "; } cout<<"\n"; } getch(); }