R
rami-madini
given two square matrices A & B of size n. based on user selection,
preform one of the following operations:
* Note A={a b} inverse A^-1= (1/ad-be){d -b}
{c d} {-c a}
this is my project for the c++ class I have read all of the instructions that i had received in my last
this is my program help me pleas to improve it and thank you all
#include<iostream>
using namespace std;
void main()
{
float A[10][10], B[10][10], C[10][10],h; int i, j, k, m, n, x, y, Select, c1;
cout<<"Welcome to the matrix calculator \n";
again:
cout<<endl<<endl<<endl;
cout<<"Select One Operation : \n"
"(1)Addition, Subtraction, or Multiplication of A & B\n "
"(2)Transpose of A or B\n"
"(3)Inverse of A or B only when n= 2\n";
cin>>Select;
if(Select==1)
{
cout<<"choose: (1) For Addition.\t(2) For Subtraction.\t(3) For Multiplication.\n";
cin>>c1;
if(c1==1)
{
cout<<"Enter matrix dimensions:\n";
cin>>m>>n;
cout<<"\nEnter Matrix A values:\n";
for(i=0; i<m; i++)
{
for(j=0; j<n; j++)
{
cin>>A[j];
}
}
cout<<"\nEnter Matrix B values:\n";
for(i=0; i<m; i++)
{
for(j=0; j<n; j++)
{
cin>>B[j];
}
}
cout<<"\nSum of Matrix A and B:";
for(i=0; i<m; i++)
{
cout<<"\n";
for(j=0; j<n; j++)
{
C[j]=A[j]+B[j];
cout<<C[j]<<"\t";
}
}
}
else if(c1==2)
{
cout<<"Enter matrix dimensions:\n";
cin>>m>>n;
cout<<"\nEnter Matrix A values:\n";
for(i=0; i<m; i++)
{
for(j=0; j<n; j++)
{
cin>>A[j];
}
}
cout<<"\nEnter Matrix B values:\n";
for(i=0; i<m; i++)
{
for(j=0; j<n; j++)
{
cin>>B[j];
}
}
cout<<"\nSubtraction of Matrix A and B:";
for(i=0; i<m; i++)
{
cout<<"\n";
for(j=0; j<n; j++)
{
C[j]=A[j]-B[j];
cout<<C[j]<<"\t";
}
}
}
else if(c1==3)
{
cout<<"Enter Matrix A dimensions:\n";
cin>>m>>n;
cout<<"\nEnter Matrix A values:\n";
for( i = 0 ; i < m ; i++)
{
for( j = 0 ; j < n ; j++)
{
cin>>A[j];
C[j]=0;
}
}
cout<<"Enter Matrix B dimensions:\n";
cin>>x>>y;
cout<<"\nEnter Matrix B values:\n";
for( i = 0 ; i < x ; i++)
{
for( j = 0 ; j < y ; j++)
{
cin>>B[j];
}
}
for( i = 0 ; i < m ; i++)
{
for( j = 0 ; j < y ; j++)
{
for( k = 0 ;k < n ; k++)
{
C[j] += A[k]*B[k][j];
}
}
}
cout<<"\nThe Multiplication of Matrix A and B:";
for( i = 0 ; i < m ; i++)
{
cout<<"\n";
for( j = 0 ; j < y ; j++)
{
cout<<C[j]<<"\t";
}
}
}
}
else if(Select==2)
{
cout<<"Enter Matrix dimensions:\n";
cin>>m>>n;
cout<<"\nEnter Matrix Values:\n";
for(i=0; i<m; i++)
{
for(j=0; j<n; j++)
{
cin>>A[j];
B[j]=A[j];
}
}
cout<<"\nThe transpose of the Matrix :";
for(i=0; i<n; i++)
{
cout<<"\n";
for(j=0; j<m; j++)
{
cout<<B[j]<<"\t";
}
}
}
else if(Select==3)
{
cout<<"Enter Matrix dimensions:\n";
cin>>m>>n;
if(n==2)
{
cout<<"\nEnter Matrix Values:\n";
for(i=0; i<m; i++)
{
for(j=0; j<n; j++)
{
cin>>A[j];
}
}
cout<<"\nThe Inverse of the Matrix :\n";
h=(1/(((A[0][0])*(A[1][1]))-((A[0][1])*(A[1][0]))));
cout<<(A[1][1]*h)<<"\t"<<(-A[0][1]*h)<<"\n"<<(-A[1][0]*h)<<"\t"<<(A[0][0]*h);
}
else
cout<<"Invaled Input! Please read the statment again carefully this time ";
}
else
cout<<"Invaled Input! Please read the statment again carefully this time ";
goto again;
cout<<endl;
system("pause");
}
and thank you
preform one of the following operations:
* Note A={a b} inverse A^-1= (1/ad-be){d -b}
{c d} {-c a}
this is my project for the c++ class I have read all of the instructions that i had received in my last
this is my program help me pleas to improve it and thank you all
#include<iostream>
using namespace std;
void main()
{
float A[10][10], B[10][10], C[10][10],h; int i, j, k, m, n, x, y, Select, c1;
cout<<"Welcome to the matrix calculator \n";
again:
cout<<endl<<endl<<endl;
cout<<"Select One Operation : \n"
"(1)Addition, Subtraction, or Multiplication of A & B\n "
"(2)Transpose of A or B\n"
"(3)Inverse of A or B only when n= 2\n";
cin>>Select;
if(Select==1)
{
cout<<"choose: (1) For Addition.\t(2) For Subtraction.\t(3) For Multiplication.\n";
cin>>c1;
if(c1==1)
{
cout<<"Enter matrix dimensions:\n";
cin>>m>>n;
cout<<"\nEnter Matrix A values:\n";
for(i=0; i<m; i++)
{
for(j=0; j<n; j++)
{
cin>>A[j];
}
}
cout<<"\nEnter Matrix B values:\n";
for(i=0; i<m; i++)
{
for(j=0; j<n; j++)
{
cin>>B[j];
}
}
cout<<"\nSum of Matrix A and B:";
for(i=0; i<m; i++)
{
cout<<"\n";
for(j=0; j<n; j++)
{
C[j]=A[j]+B[j];
cout<<C[j]<<"\t";
}
}
}
else if(c1==2)
{
cout<<"Enter matrix dimensions:\n";
cin>>m>>n;
cout<<"\nEnter Matrix A values:\n";
for(i=0; i<m; i++)
{
for(j=0; j<n; j++)
{
cin>>A[j];
}
}
cout<<"\nEnter Matrix B values:\n";
for(i=0; i<m; i++)
{
for(j=0; j<n; j++)
{
cin>>B[j];
}
}
cout<<"\nSubtraction of Matrix A and B:";
for(i=0; i<m; i++)
{
cout<<"\n";
for(j=0; j<n; j++)
{
C[j]=A[j]-B[j];
cout<<C[j]<<"\t";
}
}
}
else if(c1==3)
{
cout<<"Enter Matrix A dimensions:\n";
cin>>m>>n;
cout<<"\nEnter Matrix A values:\n";
for( i = 0 ; i < m ; i++)
{
for( j = 0 ; j < n ; j++)
{
cin>>A[j];
C[j]=0;
}
}
cout<<"Enter Matrix B dimensions:\n";
cin>>x>>y;
cout<<"\nEnter Matrix B values:\n";
for( i = 0 ; i < x ; i++)
{
for( j = 0 ; j < y ; j++)
{
cin>>B[j];
}
}
for( i = 0 ; i < m ; i++)
{
for( j = 0 ; j < y ; j++)
{
for( k = 0 ;k < n ; k++)
{
C[j] += A[k]*B[k][j];
}
}
}
cout<<"\nThe Multiplication of Matrix A and B:";
for( i = 0 ; i < m ; i++)
{
cout<<"\n";
for( j = 0 ; j < y ; j++)
{
cout<<C[j]<<"\t";
}
}
}
}
else if(Select==2)
{
cout<<"Enter Matrix dimensions:\n";
cin>>m>>n;
cout<<"\nEnter Matrix Values:\n";
for(i=0; i<m; i++)
{
for(j=0; j<n; j++)
{
cin>>A[j];
B[j]=A[j];
}
}
cout<<"\nThe transpose of the Matrix :";
for(i=0; i<n; i++)
{
cout<<"\n";
for(j=0; j<m; j++)
{
cout<<B[j]<<"\t";
}
}
}
else if(Select==3)
{
cout<<"Enter Matrix dimensions:\n";
cin>>m>>n;
if(n==2)
{
cout<<"\nEnter Matrix Values:\n";
for(i=0; i<m; i++)
{
for(j=0; j<n; j++)
{
cin>>A[j];
}
}
cout<<"\nThe Inverse of the Matrix :\n";
h=(1/(((A[0][0])*(A[1][1]))-((A[0][1])*(A[1][0]))));
cout<<(A[1][1]*h)<<"\t"<<(-A[0][1]*h)<<"\n"<<(-A[1][0]*h)<<"\t"<<(A[0][0]*h);
}
else
cout<<"Invaled Input! Please read the statment again carefully this time ";
}
else
cout<<"Invaled Input! Please read the statment again carefully this time ";
goto again;
cout<<endl;
system("pause");
}
and thank you