#include<iostream.h>
#include<process.h>
#include<conio.h>
void main()
{
int a[10][10],b[10][10],c[10][10],rowa,cola,rowb,colb,i,j,k;
cout<<"enter the data for matrix A\n";
cout<<"enter the number of rows=";
cin>>rowa;
cout<<"enter the number of coloumns=";
cin>>cola;
cout<<"enter the data for matrix B\n";
cout<<"enter the number of rows=";
cin>>rowb;
cout<<"enter the number of coloumns=";
cin>>colb;
if(cola!=rowb)                       //checking compatibility
{
cout<<"Matrix cannot be multipied\n";
exit(0);
}
cout<<"Matrix have same order and can be multiplied\npress enter \n";
getch();
clrscr();
cout<<"enter the elements of matrix A\n";
for(i=0;i<rowa;i++)
{
for(j=0;j<cola;j++)
{
cout<<"a["<<i<<"]["<<j<<"]"<<"=";
cin>>a[i][j];                                   //reading Matrix A
}
}
cout<<"enter the elements of matrix B\n";
for(i=0;i<rowb;i++)
{
for(j=0;j<colb;j++)
{
cout<<"a["<<i<<"]["<<j<<"]"<<"=";
cin>>b[i][j];                                   //reading Matrix B
}
}
for(i=0;i<rowb;i++)
{
for(j=0;j<colb;j++)
{
c[i][j]=0;
for(k=0;k<cola;k++)
{
c[i][j]=c[i][j]+a[i][k]*b[k][j];              //multiplication of matrix
}
}
}
for(i=0;i<rowa;i++)
{
cout<<endl;
for(j=0;j<colb;j++)
{
cout<<c[i][j]<<" ";               //printing result
}
}
}

in this program first we check for compatibility of matrix weather the the number of coloumn of first matrix is equal to the number of rows of the second matrix.for adding we use the rule that for multiplication we multiply the row elements of first matrix to the coloumn elements of the second matrix.this is done by using two variable i and j for row and coloumn respectivily and then using a third variable k for adding the product of the row element and the coloumn element .k changes the coloumn number in the first matrix and also changes the row number in the second matrix.we store the rsult in matrix c .here we should note that the result is ste by step stored because of the repaeted add statemant execution were i have marked as multiplication of matrix using comment .