/* transpose of a matrix */
#include<stdio.h>
#include<conio.h>
void main()
{
int a[5][5];
int i,j,m,n,temp;
m=3;n=3;
clrscr();
printf("enter the size of the first matrix (m,n)\n");
scanf("%d%d",&m,&n);
printf("enter the elements into 1array\n");
for(i=0;i<=m-1;i++)
{
for(j=0;j<=n-1;j++)
{
scanf("%d",&a[i][j]);
}
}
//transpose logic
for(i=0;i<=m-1;i++)
{
for(j=0;j<=n-1;j++)
{
if(i<j)//swapping values above diagnols with those below diagnols
{
temp=a[i][j];
a[i][j]=a[j][i];
a[j][i]=temp;
} //end of if
}//end of inner loop
} //end of outer
//displaying the tranpose matrix
for(i=0;i<=m-1;i++)
{
for(j=0;j<=n-1;j++)
{
printf("%d\t",a[i][j]);
}//inner loop
printf("\n");
}//outer loop
getch();
}
/*
i/p:
o/p:
*/
#include<stdio.h>
#include<conio.h>
void main()
{
int a[5][5];
int i,j,m,n,temp;
m=3;n=3;
clrscr();
printf("enter the size of the first matrix (m,n)\n");
scanf("%d%d",&m,&n);
printf("enter the elements into 1array\n");
for(i=0;i<=m-1;i++)
{
for(j=0;j<=n-1;j++)
{
scanf("%d",&a[i][j]);
}
}
//transpose logic
for(i=0;i<=m-1;i++)
{
for(j=0;j<=n-1;j++)
{
if(i<j)//swapping values above diagnols with those below diagnols
{
temp=a[i][j];
a[i][j]=a[j][i];
a[j][i]=temp;
} //end of if
}//end of inner loop
} //end of outer
//displaying the tranpose matrix
for(i=0;i<=m-1;i++)
{
for(j=0;j<=n-1;j++)
{
printf("%d\t",a[i][j]);
}//inner loop
printf("\n");
}//outer loop
getch();
}
/*
i/p:
o/p:
*/
No comments:
Post a Comment