google407ec42f1ae5ff0e.html
top of page

FIND THE ADDITION AND MULTIPLICATION OF SQUARE MATIRIX IN C++

#include <iostream> using namespace std; #define MAX_SIZE 10 int n; class Matrix { int item[MAX_SIZE][MAX_SIZE]; public: void get_matrix(void); void display_matrix(void); Matrix add(Matrix m); void mul(Matrix &mat, Matrix m); }; void Matrix :: get_matrix(void) { cout<<"\n Enter the order of square matrix(nXn):"<<endl; cin>>n; cout<<"\n enter the elements of matrix"<<endl; for(int i=0;i<n;i++) for(int j=0;j<n;j++) cin>>item[i][j]; } void Matrix :: display_matrix(void) { cout<<"\nThe elements of matrix is:"<<endl; for(int i=0; i<n;i++) { for(int j=0;j<n;j++) cout<<item[i][j]<<"\t"; cout<<endl; } } Matrix Matrix :: add(Matrix m) { Matrix temp; for(int i=0; i<n;i++) for(int j=0;j<n;j++) temp.item[i][j]=item[i][j]+m.item[i][j]; return (temp); } void Matrix :: mul(Matrix &rm,Matrix m) { for(int i=0; i<n;i++) for(int j=0; i<n;j++) { rm.item[i][j]=0; for(int k=0;k<n;k++) rm.item[i][j]=rm.item[i][j]+item[i][k]*rm.item[k][j]; } } int main() { Matrix X,Y,Rrsult; cout<<"Matrix X:"<<endl; X.get_matrix(); cout<<"Matrix Y:"<<endl; Y.get_matrix(); cout<<"\n Addition of X & Y:"<<endl; Result=X.add(Y); Result.display_matrix(); cout<<"\n Multyplication of X & Y:"<<endl; X.mul(Result,Y); Result.display_matruix(); }

3 views0 comments

Recent Posts

See All

Comments


bottom of page