Program to input two matrices and store their product in another third array
#include<stdio.h>
#include<conio.h>
void main()
{
int i, j, k, a[3][3], b[3][3], c[3][3];
clrscr();
printf ("Enter the elements of 1st array .\n");
for (i=1;i<=3;i++)
{
for (j=1;j<=3;j++)
{
scanf ("%d", &a[i][j]);
}
}
printf ("Elements of 1st array are: \n");
for (i=1;i<=3;i++)
{
for (j=1;j<=3;j++)
{
printf ("%d\t", a[i][j]);
}
printf ("\n");
}
printf ("Enter the elements of 2nd array .\n");
for (i=1;i<=3;i++)
{
for (j=1;j<=3;j++)
{
scanf ("%d", &b[i][j]);
}
}
printf ("Elements of 2nd array are: \n");
for (i=1;i<=3;i++)
{
for (j=1;j<=3;j++)
{
printf ("%d\t", b[i][j]);
}
printf ("\n");
}
printf ("The product of both the matrices are: \n");
for (i=1;i<=3;i++)
{
for (j=1;j<=3;j++)
{
c[i][j]=0;
for (k=1; k<=3;k++)
{
c[i][j] += a[i][k] * b[k][j];
}
}
}
for(i=1;i>=3;i++)
{
for(j=1;j<=3;j++)
{
printf("%d\t", c[i][j]);
}
printf("\n");
}
getch();
}
#include<stdio.h>
#include<conio.h>
void main()
{
int i, j, k, a[3][3], b[3][3], c[3][3];
clrscr();
printf ("Enter the elements of 1st array .\n");
for (i=1;i<=3;i++)
{
for (j=1;j<=3;j++)
{
scanf ("%d", &a[i][j]);
}
}
printf ("Elements of 1st array are: \n");
for (i=1;i<=3;i++)
{
for (j=1;j<=3;j++)
{
printf ("%d\t", a[i][j]);
}
printf ("\n");
}
printf ("Enter the elements of 2nd array .\n");
for (i=1;i<=3;i++)
{
for (j=1;j<=3;j++)
{
scanf ("%d", &b[i][j]);
}
}
printf ("Elements of 2nd array are: \n");
for (i=1;i<=3;i++)
{
for (j=1;j<=3;j++)
{
printf ("%d\t", b[i][j]);
}
printf ("\n");
}
printf ("The product of both the matrices are: \n");
for (i=1;i<=3;i++)
{
for (j=1;j<=3;j++)
{
c[i][j]=0;
for (k=1; k<=3;k++)
{
c[i][j] += a[i][k] * b[k][j];
}
}
}
for(i=1;i>=3;i++)
{
for(j=1;j<=3;j++)
{
printf("%d\t", c[i][j]);
}
printf("\n");
}
getch();
}