Respuesta :
Answer:
C++ code is explained below
Explanation:
#include<iostream>
using namespace std;
//Function Declarations
void add();
void sub();
void mul();
//Main Code Displays Menu And Take User Input
int main()
{
 int choice;
 cout << "\nMenu";
 cout << "\nChoice 1:addition";
 cout << "\nChoice 2:subtraction";
 cout << "\nChoice 3:multiplication";
 cout << "\nChoice 0:exit";
Â
 cout << "\n\nEnter your choice: ";
Â
 cin >> choice;
Â
 cout << "\n";
Â
 switch(choice)
 {
   case 1: add();
       break;
      Â
   case 2: sub();
       break;
      Â
   case 3: mul();
       break;
  Â
   case 0: cout << "Exited";
       exit(1);
  Â
   default: cout << "Invalid";   Â
 }
 main(); Â
}
//Addition Of Matrix
void add()
{
 int rows1,cols1,i,j,rows2,cols2;
Â
 cout << "\nmatrix1 # of rows: ";
 cin >> rows1;
Â
 cout << "\nmatrix1 # of columns: ";
 cin >> cols1;
Â
  int m1[rows1][cols1];
Â
 //Taking First Matrix
 for(i=0;i<rows1;i++)
   for(j=0;j<cols1;j++)
   {
     cout << "\nEnter element (" << i << "," << j << "): ";
     cin >> m1[i][j];
     cout << "\n";
   }
 //Printing 1st Matrix
 for(i=0;i<rows1;i++)
 {
   for(j=0;j<cols1;j++)
     cout << m1[i][j] << " ";
   cout << "\n";
 }
  Â
 cout << "\nmatrix2 # of rows: ";
 cin >> rows2;
Â
 cout << "\nmatrix2 # of columns: ";
 cin >> cols2;
Â
 int m2[rows2][cols2];
 //Taking Second Matrix
 for(i=0;i<rows2;i++)
   for(j=0;j<cols2;j++)
   {
     cout << "\nEnter element (" << i << "," << j << "): ";
     cin >> m2[i][j];
     cout << "\n";
   }
 //Displaying second Matrix
 cout << "\n";
 for(i=0;i<rows2;i++)
 {
   for(j=0;j<cols2;j++)
     cout << m2[i][j] << " ";
   cout << "\n";
 }
 //Displaying Sum of m1 & m2
 if(rows1 == rows2 && cols1 == cols2)
 {
   cout << "\n";
   for(i=0;i<rows1;i++)
   {
     for(j=0;j<cols1;j++)
       cout << m1[i][j]+m2[i][j] << " ";
     cout << "\n"; Â
   }
 }
 else
   cout << "operation is not supported";
  Â
 main();
Â
}
void sub()
{
 int rows1,cols1,i,j,k,rows2,cols2;
 cout << "\nmatrix1 # of rows: ";
 cin >> rows1;
Â
 cout << "\nmatrix1 # of columns: ";
 cin >> cols1;
Â
  int m1[rows1][cols1];
Â
 for(i=0;i<rows1;i++)
   for(j=0;j<cols1;j++)
   {
     cout << "\nEnter element (" << i << "," << j << "): ";
     cin >> m1[i][j];
     cout << "\n";
   }
Â
 for(i=0;i<rows1;i++)
 {
   for(j=0;j<cols1;j++)
     cout << m1[i][j] << " ";
   cout << "\n";
 }
  Â
 cout << "\nmatrix2 # of rows: ";
 cin >> rows2;
Â
 cout << "\nmatrix2 # of columns: ";
 cin >> cols2;
Â
 int m2[rows2][cols2];
Â
 for(i=0;i<rows2;i++)
   for(j=0;j<cols2;j++)
   {
     cout << "\nEnter element (" << i << "," << j << "): ";
     cin >> m2[i][j];
     cout << "\n";
   }
Â
 for(i=0;i<rows2;i++)
 {
   for(j=0;j<cols2;j++)
     cout << m1[i][j] << " ";
   cout << "\n";
 }
 cout << "\n";
 //Displaying Subtraction of m1 & m2
 if(rows1 == rows2 && cols1 == cols2)
 {
   for(i=0;i<rows1;i++)
   {
     for(j=0;j<cols1;j++)
       cout << m1[i][j]-m2[i][j] << " ";
     cout << "\n"; Â
   }
 }
 else
   cout << "operation is not supported";
  Â
 main();
Â
}
void mul()
{
 int rows1,cols1,i,j,k,rows2,cols2,mul[10][10];
 cout << "\nmatrix1 # of rows: ";
 cin >> rows1;
Â
 cout << "\nmatrix1 # of columns: ";
 cin >> cols1;
Â
  int m1[rows1][cols1];
Â
 for(i=0;i<rows1;i++)
   for(j=0;j<cols1;j++)
   {
     cout << "\nEnter element (" << i << "," << j << "): ";
     cin >> m1[i][j];
     cout << "\n";
   }
 cout << "\n";
 for(i=0;i<rows1;i++)
 {
   for(j=0;j<cols1;j++)
     cout << m1[i][j] << " ";
   cout << "\n";
 }
  Â
 cout << "\nmatrix2 # of rows: ";
 cin >> rows2;
Â
 cout << "\nmatrix2 # of columns: ";
 cin >> cols2;
Â
 int m2[rows2][cols2];
Â
 for(i=0;i<rows2;i++)
   for(j=0;j<cols2;j++)
   {
     cout << "\nEnter element (" << i << "," << j << "): ";
     cin >> m2[i][j];
     cout << "\n";
   }
 cout << "\n";
 //Displaying Matrix 2
 for(i=0;i<rows2;i++)
 {
   for(j=0;j<cols2;j++)
     cout << m2[i][j] << " ";
   cout << "\n";
 }
  Â
 if(cols1!=rows2)
   cout << "operation is not supported";
 else
 {
   //Initializing results as 0
   for(i = 0; i < rows1; ++i)
 for(j = 0; j < cols2; ++j)
 mul[i][j]=0;
// Multiplying matrix m1 and m2 and storing in array mul.
 for(i = 0; i < rows1; i++)
 for(j = 0; j < cols2; j++)
 for(k = 0; k < cols1; k++)
 mul[i][j] += m1[i][k] * m2[k][j];
// Displaying the result.
 cout << "\n";
 for(i = 0; i < rows1; ++i)
   for(j = 0; j < cols2; ++j)
   {
   cout << " " << mul[i][j];
   if(j == cols2-1)
   cout << endl;
   }
   } Â
 main();
 }