C Program for dynamic memory allocations (Product of two matrices)
Product of two matrices
Program:-
#include <stdio.h>
#include<conio.h>
void main()
{
int a[3][3],b[3][3],c[3][3];
int i,j,k,l = 1,m = 2;
clrscr();
printf("---------------Enter the first matrix A--------------\n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
gotoxy(l,m);
scanf("%d",&a[i][j]);
i = l+6;
}
m = m+1;
l=1;
}
printf("---------------Enter the first matrix B---------------\n");
m=m+1;
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
gotoxy(l,m);
scanf("%d",&b[i][j]);
i = l+6;
}
m = m+1;
l = 1;
}
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
c[i][j] = 0;
for(k=0;k<3;k++)
{
c[i][j] += a[i][k] * b[k][j];
}
}
}
printf("\n\n----------The product of two matrix--------------- \n\n" );
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
printf("\t%d\t",c[i][j]);
if(j==2)
{
printf("\n\n");
}
}
}
getch();
}
Output:
-----------------------Enter the first matrix A--------------
1 2 3
2 3 4
3 4 5
----------------Enter the first matrix B---------------
1 2 3
3 4 5
2 3 4
----------The product of two matrix---------------
13 19 25
19 28 37
25 37 49
No comments:
Post a Comment