Skip to main content
C++ Program to Add 3X3 Two Matrix using for loop
A Simple C++ program to add two Matrices
#include<iostream>
using namespace std;
int main()
{
int a[3][3], b[3][3], ab[3][3];
int z=3, x=3;
cout<<"\nEnter elements of 1st matrix:\n";
for(int i=0; i<z; i++)
{
for(int j=0; j<x; j++)
{
cin>>a[i][j];
}
}
cout<<"\nEnter elements of 2st matrix:\n";
for(int i=0; i<z; i++)
{
for(int j=0; j<x; j++)
{
cin>>b[i][j];
}
}
//Adding Two matrices
for(int i=0; i<z; i++)
{
for(int j=0; j<x; j++)
{
ab[i][j]=a[i][j]+b[i][j];
}
}
//Displaying the Result
for(int i=0; i<z; i++)
{
for(int j=0; j<x; j++)
{
cout<<ab[i][j]<<" ";
}
cout<<endl;
}
}