Matrix Transpose

Matrix Transpose

Welcome to the World of Online Learning:

Hello Friends “This blog helps you to learn C programming concepts. You can learn C language at your own speed and time. One can learn concepts of C language by practicing various programs given on various pages of this blog. Enjoy the power of Self-learning using the Internet.”

Matrix Transpose
Matrix Transpose

Write a C program to Matrix Transpose

PROGRAM: Matrix Transpose

/* Transpose the matrix */
#include<stdio.h>

int main()
{
 int a[4][4],i,j,b;

 for(i=0;i<4;i++)
 {
  printf("\nEnter elements of %d row of Matrix: ",i+1);
  for(j=0;j<4;j++)
   scanf("%d",&a[i][j]);
 }
 
 for(i=0;i<4;i++)
 {
  for(j=i+1;j<4;j++)
  {
   b=a[i][j];
   a[i][j]=a[j][i];
   a[j][i]=b;
  }
 }

 printf("\nTransposed Matrix:\n\n");
 for(i=0;i<4;i++)
 {
  for(j=0;j<4;j++)
   printf("%4d",a[i][j]);
  printf("\n");
 }
 return 0;
}

Leave a Reply

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