About Me

My photo
Raipur, Chhattisgarh, India
Hi , I am Amit Thakur. I have worked as a QA Engineer for two years and as a Java Developer for one year in NIHILENT TECHNOLOGIES PVT. LTD., Pune.Currently I am working as DEAN (Research & Development) in Bhilai Institute of Technology, Raipur.

Monday, September 2, 2013

Program to find Transpose of Given Square Matrix

#include<stdio.h>
#include<conio.h>
void main()
{
 int a[10][10],m,i,j,temp;
 /* actual size of matrix is m*n
 i,j  - for scanning of array
 temp - for interchanging of a[i][j] and a[j][i] */

 printf("n Enter the size of matrix :");
 scanf("%d",&m);

 /* Reading elements of matrix */

 printf("n Enter the values a:");

 for(i=0;i<m;i++)
  for(j=0;j<m;j++)
     scanf("%d",&a[i][j]);

 //to print original square matrix

 printf("\nGiven square matrix is");

 for(i=0;i<m;i++)
  {
  printf("n");
     for(j=0 ; j 〈 m ; j++)
          printf("%d\t",a[i][j]);
 }
 /* Find transpose */

 for(i=1;i<m;i++)
  for(j=0;j<i;j++)
   {
   temp=a[i][j];
   a[i][j]=a[j][i];
   a[j][i]=temp;
   }
 /* printing of all elements of final matrix */

 printf("nTranspose matrix is :");

 for(i=0;i 〈 m;i++)
 {
  printf("\n");
  for(j=0;j<m;j++)
      printf("%d\t",a[i][j]);
 }
 getch();
}

No comments: