/* To prove Transpose(AB)=Transpose B x Transpose A */
#include<stdio.h>
#include<math.h>
int main()
{
int i, j, n, m, p, k, a[20] [20], b[20] [20], e[20] [20], flag=0;
int transpose[20][20], at[20] [20], bt[20] [20], atbt[20] [20];
printf("Enter order of the matrix A:\n");
scanf("%d%d", &m, &n);
printf("Enter order of the matrix B:\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");
}
/*To determine transpose of matrix A*/
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
at[j][i]=a[i][j];
}
}
printf("Transpose of matrix A:\n");
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
printf("%10d", at[i][j]);
}
printf("\n\n");
}
printf("Enter 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 determine transpose of matrix B*/
for(i=0;i<n;i++)
{
for(j=0;j<p;j++)
{
bt[j][i]=b[i][j];
}
}
printf("Transpose of matrix B:\n");
for(i=0;i<p;i++)
{
for(j=0;j<n;j++)
{
printf("%10d", bt[i][j]);
}
printf("\n\n");
}
/*To determine multiplication of (transposeB)*(transposeA)*/
for(i=0;i<p;i++)
{
for(j=0;j<m;j++)
{
atbt[i] [j]=0;
for(k=0;k<n;k++)
atbt[i] [j]=atbt[i] [j]+bt[i] [k]*at[k] [j];
}
}
/* 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 AB is:\n");
for(i=0;i<m;i++)
{
for(j=0;j<p;j++)
printf("%10d\t", e[i] [j]);
printf("\n");
}
/*To determine transpose of AB*/
for(i=0;i<m;i++)
{
for(j=0;j<p;j++)
{
transpose[j][i]=e[i][j];
}
}
printf("Transpose of matrix AB:\n");
for(i=0;i<p;i++)
{
for(j=0;j<m;j++)
{
printf("%10d", transpose[i][j]);
}
printf("\n");
}
printf("Product matrix TransposeB x TransposeA is:\n");
for(i=0;i<p;i++)
{
for(j=0;j<m;j++)
printf("%10d\t", atbt[i] [j]);
printf("\n");
}
/*Checking*/
for(i=0;i<p;i++)
{
for(j=0;j<m;j++)
{
if(transpose[i][j]==atbt[i][j])
{
flag=1;
break;
}
}
}
if(flag==1)
printf("So,Transpose of matrix AB=Transpose of B * Transpose of A.\n");
else
printf("So,Transpose of matrix AB is not equal to Transpose of B * Transpose of A.\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], flag=0;
int transpose[20][20], at[20] [20], bt[20] [20], atbt[20] [20];
printf("Enter order of the matrix A:\n");
scanf("%d%d", &m, &n);
printf("Enter order of the matrix B:\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");
}
/*To determine transpose of matrix A*/
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
at[j][i]=a[i][j];
}
}
printf("Transpose of matrix A:\n");
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
printf("%10d", at[i][j]);
}
printf("\n\n");
}
printf("Enter 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 determine transpose of matrix B*/
for(i=0;i<n;i++)
{
for(j=0;j<p;j++)
{
bt[j][i]=b[i][j];
}
}
printf("Transpose of matrix B:\n");
for(i=0;i<p;i++)
{
for(j=0;j<n;j++)
{
printf("%10d", bt[i][j]);
}
printf("\n\n");
}
/*To determine multiplication of (transposeB)*(transposeA)*/
for(i=0;i<p;i++)
{
for(j=0;j<m;j++)
{
atbt[i] [j]=0;
for(k=0;k<n;k++)
atbt[i] [j]=atbt[i] [j]+bt[i] [k]*at[k] [j];
}
}
/* 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 AB is:\n");
for(i=0;i<m;i++)
{
for(j=0;j<p;j++)
printf("%10d\t", e[i] [j]);
printf("\n");
}
/*To determine transpose of AB*/
for(i=0;i<m;i++)
{
for(j=0;j<p;j++)
{
transpose[j][i]=e[i][j];
}
}
printf("Transpose of matrix AB:\n");
for(i=0;i<p;i++)
{
for(j=0;j<m;j++)
{
printf("%10d", transpose[i][j]);
}
printf("\n");
}
printf("Product matrix TransposeB x TransposeA is:\n");
for(i=0;i<p;i++)
{
for(j=0;j<m;j++)
printf("%10d\t", atbt[i] [j]);
printf("\n");
}
/*Checking*/
for(i=0;i<p;i++)
{
for(j=0;j<m;j++)
{
if(transpose[i][j]==atbt[i][j])
{
flag=1;
break;
}
}
}
if(flag==1)
printf("So,Transpose of matrix AB=Transpose of B * Transpose of A.\n");
else
printf("So,Transpose of matrix AB is not equal to Transpose of B * Transpose of A.\n");
return(0);
}
Comments
Post a Comment