recent

C Program To Find Transpose Of Given Square Matrix(2D-Array)

C Program To Find Transpose Of Given Square Matrix(2D-Array)

#include<stdio.h>

void main()
{
 
   int arr[10][10], size, i, j, temp;

   printf("Enter the size of matrix :\n");
   scanf("%d", &size);  //input from user

   printf("Enter the values a:\n");
   for (i = 0; i < size; i++)
   {
      for (j = 0; j < size; j++)
  {
         scanf("%d", &arr[i][j]);  //entry of elemrnt in 2D-array
      }
   }

   printf("Given square matrix is\n");
   for (i = 0; i < size; i++)
    {
      printf("\n");
      for (j = 0; j < size; j++)
 {
         printf("%d\t", arr[i][j]);   //print original matrix
      }
   }

   //Find transpose 
   for (i = 1; i < size; i++) {
      for (j = 0; j < i; j++) {
         temp = arr[i][j];
         arr[i][j] = arr[j][i];
         arr[j][i] = temp;
      }
   }

   printf("Transpose matrix is :\n");
   for (i = 0; i < size; i++)
   {
      printf("\n");
      for (j = 0; j < size; j++)
 {
         printf("%d\t", arr[i][j]);  //matrix after transpose
      }
   }
}
Powered by Blogger.