Image

Programs - C++ - Array

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();
}