#include
#include
void main()
{
clrscr();
int mat1[10][10],mult[10][10],mat2[10][10],i,j,n,k;
printf("Enter the size of the matrix:");
scanf("%d",&n);
printf("Enter the element of the(%d*%d) first matrix: \n\n",n,n);
//Input first matrix.
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
{
printf("Element[%d][%d]",i,j);
scanf("%d",&mat1[i][j]);
}
printf("\n");
}
printf("Enter the element of the (%d*%d) second matrix:\n\n",n,n);
// Input second matrix.
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
{
printf("Element[%d][%d]",i,j);
scanf("%d",&mat2[i][j]);
}
printf("\n");
}
//print matrix 1.
printf(" MATRIX 1 \n");
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
{
printf("%3d ",mat1[i][j]);
}
printf("\n");
}
printf("\n\n");
//print matrix 2.
printf(" MATRIX 2 \n");
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
{
printf("%3d ",mat2[i][j]);
}
printf("\n");
}
printf("The multiplication of the matrix:\n");
//Determination of the multiplication of two matrix && print.
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
{
mult[i][j]=0;
for(k=1;k<=n;k++)
{
mult[i][j]=mult[i][j]+mat1[i][k]*mat2[k][j];
}
printf("%3d ",mult[i][j]);
}
printf("\n");
}
getch();
}
0 comments:
Post a Comment