Image

Programs - C++ - Looping

Program:


#include<iostream.h>
#include<conio.h>
void main()
{
int a[2][2],b[2][2],c[2][2],n,m,i,j,k;
cout<<"
enter size of rows  :"
;
cin>>n;
cout<<"
enter size of collumns :"
;
cin>>m;
cout<<"
enter element of 2d array :"
;
for(i=1;i<=n;i++)
 {
  for(j=1;j<=m;j++)
  {
  cin>>a[i][j];
  }
 }
cout<<"
first matrix


:"
;
for(i=1;i<=n;i++)
 {
  for(j=1;j<=m;j++)
  {
  cout<<" "<<a[i][j];
  }
  cout<<"

"
;
 }
cout<<"
enter same size of rows  :"
;
cin>>n;
cout<<"
enter same size of collumns :"
;
cin>>m;
cout<<"
enter element of 2d array :"
;
for(i=1;i<=n;i++)
 {
  for(j=1;j<=m;j++)
  {
  cin>>b[i][j];
  }
 }
cout<<"
second matrix


:"
;
for(i=1;i<=n;i++)
 {
  for(j=1;j<=m;j++)
  {
  cout<<" "<<b[i][j];
  }
  cout<<"

"
;
 }
for(i=1;i<=n;i++)
 {
  for(j=1;j<=m;j++)
  {
   c[i][j]=0;
   for(k=1;k<=n;k++)
   {
   c[i][j]=c[i][j]+a[i][k]*b[k][j];
   }
  }
 }
cout<<"
multiplication of matrix is


:"
;
for(i=1;i<=n;i++)
 {
  for(j=1;j<=m;j++)
  {
  cout<<" "<<c[i][j];
  }
  cout<<"

"
;
 }
getch();
clrscr();
}