-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #70 from MonalikaKapoor/Addition-of-two-matrices
Added code for Addition of two matrices using array
- Loading branch information
Showing
1 changed file
with
59 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,59 @@ | ||
/* C++ Program to Add Two Matrices using array */ | ||
|
||
#include<iostream> | ||
using namespace std; | ||
|
||
int main() | ||
{ | ||
|
||
int arr1[5][5], arr2[5][5], arr3[5][5], sub, i, j,m,n; | ||
|
||
cout<<"Enter size of matrix ( Max:5 ) :: "; | ||
cin>>m; | ||
cout<<"\nEnter Elements to Matrix A Below :: \n"; | ||
|
||
for(i=0;i<m;i++) | ||
{ | ||
for(j=0;j<m;++j) | ||
{ | ||
cout<<"\nEnter arr1["<<i<<"]["<<j<<"] Element :: "; | ||
cin>>arr1[i][j]; | ||
} | ||
|
||
} | ||
|
||
cout<<"\nEnter Elements to Matrix B Below :: \n"; | ||
|
||
for(i=0;i<m;i++) | ||
{ | ||
for(j=0;j<m;++j) | ||
{ | ||
cout<<"\nEnter arr2["<<i<<"]["<<j<<"] Element :: "; | ||
cin>>arr2[i][j]; | ||
} | ||
|
||
} | ||
|
||
|
||
cout<<"\nAdding Matrix ( A + B ) ..... \n"; | ||
for(i=0; i<m; i++) | ||
{ | ||
for(j=0; j<m; j++) | ||
{ | ||
arr3[i][j]=arr1[i][j]+arr2[i][j]; | ||
} | ||
} | ||
|
||
cout<<"\nAfter Addition, Matrix C is :: \n"; | ||
|
||
for (i = 0; i < m; ++i) | ||
{ | ||
for (j = 0; j < m; ++j) | ||
{ | ||
cout<<"\t"<<arr3[i][j]; | ||
} | ||
printf("\n\n"); | ||
} | ||
|
||
return 0; | ||
} |