MATRIX MULTIPLICATION :
In mathematics, a matrix (plural matrices) is a rectangular array of numbers, symbols, or expressions, arranged in rows and columns. The individual items in a matrix are called its elements or entries. An example of a matrix with 2 rows and 3 columns isA matrix is a rectangular array of numbers or other mathematical objects, for which operations such as addition and multiplication are defined
Matrices are commonly written in box brackets:
THE PROGRAM IS :
#include<stdio.h>
#include<conio.h>
void main()
{
int a[10][10],b[10][10],c[10][10],i,j,k,m,n,p,q;
printf("Enter the size of the matrix A \n");
scanf("%d%d",&m,&n);
printf("Enter the size of the matrix B \n");
scanf("%d%d",&p,&q);
if(n!=p)
{
printf("Matrix multiplication is not possible \n");
}
else
{
printf("Enter the elements of matrix A \n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
scanf("%d",&a[i][j]);
}
}
printf("Enter the elements of matrix B \n");
for(i=0;i<p;i++)
{
for(j=0;j<q;j++)
{
scanf("%d",&b[i][j]);
}
}
for(i=0;i<m;i++)
{
for(j=0;j<q;j++)
{
c[i][j]=0;
for(k=0;k<n;k++)
{
c[i][j]=c[i][j]+a[i][k]*b[k][j];
}
}
}
printf("Matrix A is \n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
printf(" %d ",a[i][j]);
}
printf("\n");
}
printf("The Matrix B is \n");
for(i=0;i<p;i++)
{
for(j=0;j<q;j++)
{
printf(" %d ",b[i][j]);
}
printf("\n");
}
printf("The resultant matrix is \n");
for(i=0;i<m;i++)
{
for(j=0;j<q;j++)
{
printf(" %d ",c[i][j]);
}
printf("\n");
}
}
getch();
}
#include<conio.h>
void main()
{
int a[10][10],b[10][10],c[10][10],i,j,k,m,n,p,q;
printf("Enter the size of the matrix A \n");
scanf("%d%d",&m,&n);
printf("Enter the size of the matrix B \n");
scanf("%d%d",&p,&q);
if(n!=p)
{
printf("Matrix multiplication is not possible \n");
}
else
{
printf("Enter the elements of matrix A \n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
scanf("%d",&a[i][j]);
}
}
printf("Enter the elements of matrix B \n");
for(i=0;i<p;i++)
{
for(j=0;j<q;j++)
{
scanf("%d",&b[i][j]);
}
}
for(i=0;i<m;i++)
{
for(j=0;j<q;j++)
{
c[i][j]=0;
for(k=0;k<n;k++)
{
c[i][j]=c[i][j]+a[i][k]*b[k][j];
}
}
}
printf("Matrix A is \n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
printf(" %d ",a[i][j]);
}
printf("\n");
}
printf("The Matrix B is \n");
for(i=0;i<p;i++)
{
for(j=0;j<q;j++)
{
printf(" %d ",b[i][j]);
}
printf("\n");
}
printf("The resultant matrix is \n");
for(i=0;i<m;i++)
{
for(j=0;j<q;j++)
{
printf(" %d ",c[i][j]);
}
printf("\n");
}
}
getch();
}
Just copy and paste into your Microsoft Visual C++ or Turbo C (these are program developing software)
Or else you can try this demo file and use it ...
Click HERE to download this file.
(Press ctrl+z and hit Enter to end the program)..
~NOTE~ : While executing if you get any warning then just ignore it and continue with your program...
IF FACE ANY PROBLEM DON'T FORGET TO COMMENT ...!!
No comments:
Post a Comment