Matrix Addition In CPP

#include<iostream.h>
#include<conio.h>



main()
{
clrscr();
int m[3][3],n[3][3],o[3][3];

for (int i=0;i<=2;i++)            // m input
{
	for (int j=0;j<=2;j++)
	{
	 cout <<"enter matrix elements";
	 cin >> m[i][j];
	}
}

for (i=0;i<=2;i++)              // m output
{
	for (int j=0;j<=2;j++)
	{
	cout << m[i][j] <<"   " ;
	}
	cout << endl;
}


for (i=0;i<=2;i++)        //  n input
{
for (int j=0;j<=2;j++)
	{
	 cout << "enter matrix elements" ;
	 cin >> n[i][j];
	}
}


for (i=0;i<=2;i++)         // n output
{
	for (int j=0;j<=2;j++)
	{
	cout << n[i][j] << "   ";
	}
	cout << endl;
}


for (i=0;i<=2;i++)        // o cal = m+n
{
	for (int j=0;j<=2;j++)
	{
	o[i][j]= m[i][j] + n[i][j];
	}
	cout << endl;
}


for (i=0;i<=2;i++)            // output o f o
{
	for (int j=0;j<=2;j++)
	{
	cout << o[i][j] << "   " ;
	}
	cout << endl;
}


getch();
}

 

Leave a Reply