Program for the addition of matrix in C++ and C with the flowchart
In this tutorial, we will learn about the followings;
- Flowchart of the program for the addition of matrix
- Program for the addition of matrix in C++
- Program for the addition of matrix in C
Flowchart of the program for the addition of matrix
Coming soon.
Program for the addition of matrix in C++
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
|
#include<iostream> #include<conio.h> using namespace std; int main() { int array1[3][3]; int array2[3][3]; int array3[3][3]; int x,y; cout<<"Please enter 1st matrix:\n"; for(x=0;x<3;x++) { for(y=0;y<3;y++){ cin>>array1[x][y]; } } cout<<"Please enter 2nd martrix:\n"; for(x=0;x<3;x++) { for(y=0;y<3;y++){ cin>>array2[x][y]; } } cout<<"First matrix:"; for(x=0;x<3;x++) { cout<<"\n\n"; for(y=0;y<3;y++){ cout<<array1[x][y]<<" "; } } cout<<"\nSecond matrix: "; for(x=0;x<3;x++) { cout<<"\n\n"; for(y=0;y<3;y++) cout<<array2[x][y]<<" "; } for(x=0;x<3;x++) { for(y=0;y<3;y++) array3[x][y]=array1[x][y]+array2[x][y]; } cout<<"\nFinal Matrix:\n"; for(x=0;x<3;x++) { cout<<"\n\n"; for(y=0;y<3;y++) cout<<array3[x][y]<<" "; } getch(); } |
Output
Figure: addition of matrix in CPP and c with the flowchart.
Program for the addition of matrix in C
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
|
#include<stdio.h> int main() { int array1[3][3]; int array2[3][3]; int array3[3][3]; int x,y; printf("Please enter first matrix: "); for(x=0;x<3;x++) { for(y=0;y<3;y++){ scanf("%ld", &array1[x][y]); } } printf("Please enter second matrix: "); for(x=0;x<3;x++) { for(y=0;y<3;y++){ scanf("%ld", &array2[x][y]); } } printf("\nFirst matrix: "); for(x=0;x<3;x++) { printf("\n\n"); for(y=0;y<3;y++){ printf("%ld",array1[x][y]); } } printf("\nSecond matrix:"); for(x=0;x<3;x++) { printf("\n\n"); for(y=0;y<3;y++) printf("%ld",array2[x][y]); } for(x=0;x<3;x++) { for(y=0;y<3;y++) array3[x][y]=array1[x][y]+array2[x][y]; } printf("\nFinal matrix:\n"); for(x=0;x<3;x++) { printf("\n\n"); for(y=0;y<3;y++) printf("%ld",array3[x][y]); } return 0; } |
Output

Figure: addition of matrix in CPP and c with the flowchart.