Transpose of a Sparse Matrix

#include<stdio.h>
#include<conio.h>
int main ()
{
	int i,j,a[10][10],m;
   clrscr();
   printf("How many non-zero element you want to enter: ");
   scanf("%d",&m);
   printf("Enter the Sparse Matrix:\n");
   for(i=0;i<=m;i++)
   	for(j=0;j<3;j++)
      	scanf("%d",&a[i][j]);
   //INTERCHANGE
   for(i=0;i<=m;i++)
   {
      a[i][1]=((a[i][0]+a[i][1])-(a[i][0]=a[i][1]));
   }

   //ASENDING
   for(i=1;i<m;i++)
   {
   	for(j=i+1;j<=m;j++)
      {
      	if(a[i][0]>a[j][0])
         {
         	a[i][0]=((a[i][0]+a[j][0])-(a[j][0]=a[i][0]));
            a[i][1]=((a[i][1]+a[j][1])-(a[j][1]=a[i][1]));
            a[i][2]=((a[i][2]+a[j][2])-(a[j][2]=a[i][2]));
         }
      }
   }       
   printf("\nTranspose is:\n\n");
   for(i=0;i<=m;i++)
   {
   	for(j=0;j<3;j++)
      	printf("%d ",a[i][j]);
      printf("\n");
	}
   getch();
   return 0;
}

Related posts:

Leave a Reply

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