This is a C++ program that reads two matrices from the user and adds them element-wise to create a third matrix. Here's how the program works:
The program assumes that both matrices have the same number of rows and columns. One potential improvement to the program would be to add error handling in case the user enters invalid inputs, such as non-numeric values or matrices with different dimensions.
#include<iostream> using namespace std; int main() { int row,col,m1[10][10],m2[10][10],sum[10][10]; cout<<"\nEnter the number of rows: "; cin>>row; cout<<"\nEnter the number of column: "; cin>>col; cout<<"\nEnter the elements of first 1st matrix: "; for(int i=0;i<row;i++) { for(int j=0;j<col;j++) { cin>>m1[i][j]; } } cout<<"Enter the elements of second 2nd matrix: "; for(int i=0;i<row;i++) { for(int j=0;j<col;j++) { cin>>m2[i][j]; } } cout<<"Output: "; for(int i=0;i<row;i++) { for(int j=0;j<col;j++) { sum[i][j]=m1[i][j]+m2[i][j]; cout<<sum[i][j]<<" "; } } return 0; }To download raw file Click Here
Enter the number of rows: 2 Enter the number of column: 2 Enter the elements of first 1st matrix: 1 2 3 4 Enter the elements of second 2nd matrix: 5 6 7 8 Output: 6 8 10 12
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions