0% found this document useful (0 votes)
2 views

27.1 Matrices.pdf

The document contains a C++ program that performs addition and subtraction of two 2D arrays (matrices). It initializes two matrices A and B, computes their sum and difference, and outputs the results. The program uses nested loops to iterate through the elements of the matrices.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

27.1 Matrices.pdf

The document contains a C++ program that performs addition and subtraction of two 2D arrays (matrices). It initializes two matrices A and B, computes their sum and difference, and outputs the results. The program uses nested loops to iterate through the elements of the matrices.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Program for adding and subtracting Matrices using 2D Arrays

#include<iostream>
using namespace std;

int main()
{
int A[2][3]={3,3,3,3,3,3};
int B[2][3]={1,1,1,1,1,1};
int C[2][3];

for(int i=0;i<2;i++)
{
for(int j=0;j<3;j++)
{
C[i][j]=A[i][j]+B[i][j];
}
}

for(int i=0;i<2;i++)
{
for(int j=0;j<3;j++)
{
cout<<C[i][j]<<" ";
}
cout<<endl;
}
cout<<endl;

for(int i=0;i<2;i++)
{
for(int j=0;j<3;j++)
{
C[i][j]=A[i][j]-B[i][j];
}
}

for(int i=0;i<2;i++)
{
for(int j=0;j<3;j++)
{
cout<<C[i][j]<<" ";
}
cout<<endl;
}
cout<<endl;

return 0;
}

You might also like