C program for transpose of matrix

If you are using any software then below program will not give an error, but if you are using TURBO C then you have to make some changes like: void main() and some function like clrscr() or getch().

#include<stdio.h>
#include<conio.h>
main()
{
int p[3][3];
int i,j;
printf("Enter the 3 by 3 Matrix\n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
scanf("%d",&p[i][j]);
}
}
printf("transpose of p\n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
printf("%d",p[j][i]);
printf("\n");
}
}

OUTPUT:

Enter the 3 by 3 Matrix
4 7 9
1 5 4
3 6 7
transpose of p
413
756
947

 

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.