forked from Rishabh062/Hacktoberfest2021
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Created a matrix gives the sum of 2 matrix difference multiplication and transpose of the matrix closes Rishabh062#738
- Loading branch information
1 parent
436068f
commit f33d1d0
Showing
1 changed file
with
140 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
#include <iostream> | ||
using namespace std; | ||
class matrix | ||
{ | ||
public: | ||
int a[4][4], b[4][4], c[4][4], d[4][4], r, s, i, j,k; | ||
void get(); | ||
void put(); | ||
void sum(); | ||
void diff(); | ||
void Multi(); | ||
void trans(); | ||
}; | ||
|
||
void matrix ::get() | ||
{ | ||
cout << "\n enter the no. of rows & columns\n"; | ||
cin >> r >> s; | ||
cout << "\n Enter " << r * s << " elements\n"; | ||
for (i = 0; i < r; i++) | ||
{ | ||
for (j = 0; j < s; j++) | ||
{ | ||
cin >> a[j][i]; | ||
} | ||
} | ||
cout << "\n Enter elements of second Matrix are\n"; | ||
for (i = 0; i < r; i++) | ||
{ | ||
for (j = 0; j < s; j++) | ||
{ | ||
cin >> b[j][i]; | ||
} | ||
} | ||
} | ||
void matrix ::put() | ||
{ | ||
cout << "\n Elements in the matrix are:\n"; | ||
for (i = 0; i < r; i++) | ||
{ | ||
for (j = 0; j < s; j++) | ||
{ | ||
cout << "\t" << a[i][j]; | ||
} | ||
cout << "\n"; | ||
} | ||
cout << "\n Elements in the 2nd matrix are:\n"; | ||
for (i = 0; i < r; i++) | ||
{ | ||
for (j = 0; j < s; j++) | ||
{ | ||
cout << "\t" << b[i][j]; | ||
} | ||
cout << "\n"; | ||
} | ||
} | ||
void matrix ::sum() | ||
{ | ||
cout << "Sum of Matrices 1 and 2 is\n"; | ||
for (i = 0; i < r; i++) | ||
{ | ||
for (j = 0; j < s; j++) | ||
{ | ||
c[i][j] = a[i][j] + b[i][j]; | ||
cout << c[i][j] << " "; | ||
} | ||
cout << endl; | ||
} | ||
} | ||
void matrix ::diff() | ||
{ | ||
cout << "Diffrence of Matrices 1 and 2 is\n"; | ||
for (i = 0; i < r; i++) | ||
{ | ||
for (j = 0; j < s; j++) | ||
{ | ||
d[i][j] = a[i][j] - b[i][j]; | ||
cout << d[i][j] << " "; | ||
} | ||
cout << endl; | ||
} | ||
} | ||
void matrix ::Multi() | ||
{ | ||
cout << "Multiplication of Matrices 1 and 2 is\n"; | ||
{ | ||
for(i=0;i<r;i++) | ||
{ | ||
for(j=0;j<s;j++) | ||
{ | ||
d[i][j]=0; | ||
for(k=0;k<r;k++) | ||
{ | ||
d[i][j]+=a[i][k]*b[k][j]; | ||
} | ||
} | ||
} | ||
for(i=0;i<r;i++) | ||
{ | ||
for(j=0;j<s;j++) | ||
{ | ||
cout<<d[i][j]<<" "; | ||
} | ||
cout<<"\n"; | ||
} | ||
} | ||
|
||
} | ||
void matrix ::trans() | ||
{ | ||
cout << "Transpose of the matrix is:\n"; | ||
for (i = 0; i < r; i++) | ||
{ | ||
for (j = 0; j < s; j++) | ||
{ | ||
c[i][j] = a[j][i]; | ||
cout << c[i][j] << " "; | ||
} | ||
cout << endl; | ||
} | ||
} | ||
int main() | ||
{ | ||
matrix ob; | ||
char ch; | ||
do | ||
{ | ||
ob.get(); | ||
ob.put(); | ||
ob.sum(); | ||
ob.diff(); | ||
ob.Multi(); | ||
ob.trans(); | ||
cout << "Do You want to do another set of opertions y/n??\n"; | ||
cin >> ch; | ||
} while (ch != 'n'); | ||
cout << "Thank You!!\n"; | ||
system("pause"); | ||
return 0; | ||
} |