ads

Sunday, 28 August 2016

c program for transpose of a matrix

#include<stdio.h>
#include<conio.h>
void main()
{
 int a[100][100],i,j,temp,n,m;
 clrscr();
 printf("enter how many rows and colums:");
 scanf("%d%d",&n,&m);
 printf("enter the matrix:");
 for(i=0;i<n;i++)
 {
  for(j=0;j<m;j++)
  {
   scanf("%d",&a[i][j]);
  }
 }
 printf("matrix before transpose\n");
 for(i=0;i<n;i++)
 {
  for(j=0;j<m;j++)
  {
   printf("%d\t",a[i][j]);
  }
  printf("\n");
 }
 for(i=0;i<4;i++)
 {
  for(j=0;j<4;j++)
  {
   temp=a[i][j];
   a[i][j]=a[j][i];
   a[j][i]=temp;
  }
 }
 printf("transpose of matrix:\n");
 for(i=0;i<n;i++)
 {
  for(j=0;j<m;j++)
  {
   printf("%d\t",a[j][i]);
  }
  printf("\n");
 }
 getch();
 }

No comments:

Post a Comment