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++
#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

Program for the addition of matrix in C
#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.