C Program For Transpose of Matrix

#include<stdio.h>
#include<conio.h>
void main()
{
int a[10][10],b[10][10],r1,c1,i,j,t;
clrscr();
printf(" rows and col's of 1st matrix: ");
scanf("%d%d",&r1,&c1);
printf("enter  %d * %d = %d elements of 1st matrix: ",r1,c1,r1*c1);
for(i=0;i<r1;i++)
{
 for(j=0;j<c1;j++)
 {
 scanf("%d",&a[i][j]);
 }
}


for(i=0;i<r1;i++)
{
 for(j=0;j<c1;j++)
 {
 t=a[i][j];
 a[i][j]=a[j][i];
 a[j][i]=t;
 }
}
printf("After Transpose:\n" );

for(i=0;i<r1;i++)
{
 for(j=0;j<c1;j++)
 {
 printf("%4d",a[i][j]);
 }
 printf("\n");
}

getch();
}
Bhanu Namikaze

Bhanu Namikaze is an Ethical Hacker, Security Analyst, Blogger, Web Developer and a Mechanical Engineer. He Enjoys writing articles, Blogging, Debugging Errors and Capture the Flags. Enjoy Learning; There is Nothing Like Absolute Defeat - Try and try until you Succeed.

No comments:

Post a Comment