/* Multiplication of two matices */
#include<stdio.h>
#include<math.h>
int main()
{
int i, j, n, m, p, k, a[20] [20], b[20] [20], e[20] [20];
printf("Enter order of the matrix A(mxn):\n");
scanf("%d%d", &m, &n);
printf("Enter order of the matrix B(nxp):\n");
scanf("%d%d", &n, &p);
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("\n");
}
printf("Entered Matrix A:\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
printf("%10d",a[i] [j]);
printf("\n");
}
printf("\nEnter the elements of matrix B:\n");
for(i=0;i<n;i++)
{
for(j=0;j<p;j++)
scanf("%d", &b[i] [j]);
printf("\n");
}
printf("Entered Matrix B:\n");
for(i=0;i<n;i++)
{
for(j=0;j<p;j++)
printf("%10d",b[i] [j]);
printf("\n");
}
/* To Perform matrix multiplication */
for(i=0;i<m;i++)
{
for(j=0;j<p;j++)
{
e[i] [j]=0;
for(k=0;k<n;k++)
e[i] [j]=e[i] [j]+a[i] [k]*b[k] [j];
}
}
printf("Product matrix E=A*B is:\n");
for(i=0;i<m;i++)
{
for(j=0;j<p;j++)
printf("%d\t", e[i] [j]);
printf("\n");
}
return(0);
}
#include<stdio.h>
#include<math.h>
int main()
{
int i, j, n, m, p, k, a[20] [20], b[20] [20], e[20] [20];
printf("Enter order of the matrix A(mxn):\n");
scanf("%d%d", &m, &n);
printf("Enter order of the matrix B(nxp):\n");
scanf("%d%d", &n, &p);
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("\n");
}
printf("Entered Matrix A:\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
printf("%10d",a[i] [j]);
printf("\n");
}
printf("\nEnter the elements of matrix B:\n");
for(i=0;i<n;i++)
{
for(j=0;j<p;j++)
scanf("%d", &b[i] [j]);
printf("\n");
}
printf("Entered Matrix B:\n");
for(i=0;i<n;i++)
{
for(j=0;j<p;j++)
printf("%10d",b[i] [j]);
printf("\n");
}
/* To Perform matrix multiplication */
for(i=0;i<m;i++)
{
for(j=0;j<p;j++)
{
e[i] [j]=0;
for(k=0;k<n;k++)
e[i] [j]=e[i] [j]+a[i] [k]*b[k] [j];
}
}
printf("Product matrix E=A*B is:\n");
for(i=0;i<m;i++)
{
for(j=0;j<p;j++)
printf("%d\t", e[i] [j]);
printf("\n");
}
return(0);
}
Comments
Post a Comment