Write a ‘C’ program to display the transpose of a given 3X3 matrix.
#include<stdio.h>
#include<conio.h>
void main()
{
int a[3][3],i,j;
clrscr();
printf("enter the elements\n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
scanf("%d",&a[i][j]);
}
}
printf("matrix\n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
printf("%d",a[i][j]);
}
printf("\n");
}
printf("-------------------------\n");
printf("transpose\n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
printf("%d",a[j][i]);
}
printf("\n");
}
getch();
}
#include<conio.h>
void main()
{
int a[3][3],i,j;
clrscr();
printf("enter the elements\n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
scanf("%d",&a[i][j]);
}
}
printf("matrix\n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
printf("%d",a[i][j]);
}
printf("\n");
}
printf("-------------------------\n");
printf("transpose\n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
printf("%d",a[j][i]);
}
printf("\n");
}
getch();
}
Thanks
ReplyDeleteNice code ease to understand.
Its my suggestion if possible it implement in C++. because most of the programe based on matrix available in C.
This comment has been removed by the author.
ReplyDeleteTranspose of a matrix means rotating a matrix by 90 degrees. First row will become first column and first column will become first row of matrix.
ReplyDeleteThank you very much for this code. It is very helpful.
ReplyDelete