(C++) CPP Programs - 19

Friday, December 14, 2007

19. Write a C program to read a matrix A(M*N), find the transpose of the given matrix and output both the matrix and the transposed matrix.

/* Transpose of a matrix*/

#include
#include

void main()
{
int a[5][5],m,n,i,j,opt;
clrscr();

printf("Enter the order of matrix\n\a");
scanf("%d%d",&m,&n);

printf("Enter the elements of a\n");
for(i=0;i < m;i++)
for(j=0;j < n;j++)
scanf("%d",&a[i][j]);

printf("The matrix a is\n");
for(i=0;i < m;i++)
{
for(j=0;j < n;j++)
printf("%4d",a[i][j]);
printf("\n");
}

printf("\nThe transpose is\n");
for(i=0;i < n;i++)
{
for(j=0;j < m;j++)
printf("%4d",a[j][i]);
printf("\n");
}

getch();
}

0 comments:

Post a Comment

Chitika

About This Blog

Followers

Blog Archive

  © Blogger template The Professional Template II by Ourblogtemplates.com 2009

Back to TOP