Write a program to add two matrices by using multi-dimensional arrays.

Program to add two matrices by using multi-dimensional arrays

Write a program to add two matrices by using multi-dimensional arrays.

Object: Write a program to add two matrices by using multi-dimensional arrays.

Code:

#include<iostream>
#include<conio.h>
using namespace std;
void main()
{
int sum[2][3],i,j;
int mat1[2][3]={{2,4,5},{4,5,6}};
int mat2[2][3]={{6,3,1},{3,2,6}};
cout<<“1st Matrix: \n\n”;
for(i=0;i<2;i++)
{
cout<<“[ “;
for(j=0;j<3;j++)
{
cout<<mat1[i][j]<<” “;
}
cout<<“]”<<endl;
}
cout<<“\n2nd Matrix: \n\n”;
for(i=0;i<2;i++)
{
cout<<“[ “;
for(j=0;j<3;j++)
{
cout<<mat2[i][j]<<” “;
}
cout<<“]”<<endl;
}
cout<<“\nSum of Two Matrix: \n\n”;
for(i=0;i<2;i++)
{
for(j=0;j<3;j++)
{
sum[i][j]=mat1[i][j]+mat2[i][j];
}
}
for(i=0;i<2;i++)
{
cout<<“[ “;
for(j=0;j<3;j++)
{
cout<<sum[i][j]<<” “;
}
cout<<“]”<<endl;
}
getch();
}

Output:

Write a program to add two matrices by using multi-dimensional arrays.

M.A Siddiqui

Hi, I am M.A Siddiqui. I'm a Computer Science Student, In this website, I'm teaching you Multiple languages and provides Projects and other Subjects Notes.

You may also like...

1 Response

  1. June 14, 2020

    […] Write a program to add two matrices by using multi-dimensional arrays. […]

Leave a Reply

Your email address will not be published. Required fields are marked *