Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- class Matrix{
- public:
- Matrix(int n){
- this->n=n;
- int i,j;
- cout<<"Introduce matricea:";
- for(i=0;i<n;i++)
- for(j=0;j<n;j++)
- cin>>a[i][j];
- }
- void toString(){
- for(int i=0;i<n;i++){
- cout<<endl;
- for(int j=0;j<n;j++)
- cout<<this->a[i][j]<<" ";
- }
- }
- Matrix adunare(Matrix b){
- if(b.n == this->n){
- int i,j;
- for(i=0;i<n;i++)
- for(j=0;j<n;j++)
- b.a[i][j]=this->a[i][j]+b.a[i][j];
- }
- return b;
- }
- Matrix inmultire(Matrix b){
- if(b.n == this->n){
- int i,j,l;
- int c[100][100];
- for(i=0;i<n;i++)
- for(j=0;j<n;j++)c[i][j]=0;
- for(i=0;i<n;i++)
- for(j=0;j<n;j++)
- for(l=j;l<=n;l++){
- c[i][j]=this->a[i][l]+b.a[l][j];
- }
- for(i=0;i<n;i++){
- for(j=0;j<n;j++){
- b.a[i][j]=c[i][j];
- }
- }
- }
- return b;
- }
- private:
- int a[100][100],n;
- };
- int main()
- {
- Matrix a = Matrix(2);
- Matrix b = Matrix(2);
- a.toString();
- b=a.inmultire(b);
- b.toString();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement