Wednesday 4 February 2015

Write a c++ program to add two matrix using 2-Darrays


Write a c++ program to add two matrix using 2-Darrays
#include<iostream>
using namespace std;
int main(){
const int row=2,col=2;
cout<<"Size of Matrices : "<<row<<" X "<<col<<endl;
cout<<"Enter Value For First Matrix:"<<endl;
int first[row][col], second[row][col];
int i,j;
fori=0;i<row;i++){
    cout<<"Enter value for row number: "<<i+1<<endl;
    forj=0;j<col;j++){
        cin>>first[i][j];
    }
}
cout<<"\n\n\nEnter Value For Second Matrix:"<<endl;
fori=0;i<row;i++){

    cout<<"Enter value for row number: "<<i+1<<endl;
    forj=0;j<col;j++){
        cin>>second[i][j];    }
}
fori=0;i<row;i++)
{
    forj=0;j<col;j++){
        first[i][j]=first[i][j]+second[i][j];
    }
}

cout<<"\n\n\t\tResultant Matrix:"<<endl;
fori=0;i<row;i++){
    cout<< endl;
    forj=0;j<col;j++){
        cout<<"\t\t"<<first[i][j]<<"    ";
    }
}
return 0;
}

No comments:

Post a Comment