Objective: Write a program to add or multiply two matrices. General Comments: Ma
ID: 3652556 • Letter: O
Question
Objective: Write a program to add or multiply two matrices. General Comments: Make sure the program follows the programming practices discussed in class. Use separate subroutines for the matrix addition and matrix multiplication. Program Description & Requirements: The program needs to take two matrices provided by the user and either add or multiply them together as stated by the user. Specifically the program must do the following: i) Write to the screen the name of the program ii) Ask the user which matrix operation is desired, either addition or multiplication. Specifically the operations are: A+B AB
PLEASE JUST DO i AND ii, I JUST WANT TO KNOW HOW TO PROGRAM THOSE TWO TO THE OUTPUT SCREEN THANKS
Explanation / Answer
Please rate this:
#include<iostream.h>
int main()
{
double A[10][10],B[10][10],D[10][10],rA,cA,rB,cB;
int reply;
cout<<"Enter the row order of the matrix A: ";
cin>>rA;
cout<<"Enter the column order of the matrix A: ";
cin>>cA;
cout<<"Enter elements of Matrix A:";
for(int i=0;i<rA;i++)
{
for(int j=0;j<cB;j++)
{
cin>>A[i][j];
}
}
cout<<"Enter the row order of the matrix A: ";
cin>>rB;
cout<<"Enter the column order of the matrix A: ";
cin>>cB;
for(int k=0;k<rB;k++)
{
for(int l=0;l<cB;l++)
{
cin>>B[k][l];
}
}
cout<< " Decide To Do Addition or Multiplication: Press '1' for Addition & '2' for Multiplication";
cin>>reply;
switch(reply)
{
case '1':
cout<<"Matrix Addition of A+B is : ";
if(rA==rB && cA==cB)
{
for(int e=0;e<rA;e++)
{
for(int f=0;f<cA;f++)
{
cout<<(A[e][f]+B[e][f])<<endl;
}
cout<<" ";
}
}
else
cout<<"Not possible for the given Matricess";
cout<<"Multiplication of a given Matricess ";
break;
case '2':if(cA==rB)
{
for(int g=0;g<rA;g++)
{
for(int h=0;h<cA;h++)
{
D[g][h]=0;
for(int z=0;z<cA;z++)
{
D[g][h]+=A[g][z]*B[z][g];
cout<<D[g][h];
}
}
cout<<" ";
}
}
else
cout<<"Not possible for the given Matricess ";
break;
default: cout << "Wrong Input";
break;
}
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.